Skip to content

Commit 8bf9ae0

Browse files
committed
fix data mut
1 parent d28ccb9 commit 8bf9ae0

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["algorithm-macro"]
33

44
[package]
55
name = "algorithm"
6-
version = "0.1.10"
6+
version = "0.1.11"
77
edition = "2021"
88
authors = ["tickbh <tickdream125@hotmail.com>"]
99
description = "about algorithm data structure, now has ttl with lru/lru-k/lfu/arc and slab/rbtree/roaring_bitmap/timer_wheelss, 关于算法常用的数据结构"

src/buf/binary_mut.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,20 @@ impl BinaryMut {
289289
}
290290
}
291291

292+
/// 获取可读且已初始化的数据
293+
///
294+
/// # Examples
295+
///
296+
/// ```
297+
/// use algorithm::buf::{BinaryMut, Bt, BtMut};
298+
///
299+
/// let mut buf = BinaryMut::with_capacity(0);
300+
/// assert!(buf.data_mut().len() != 0);
301+
///
302+
/// ```
292303
pub fn data_mut(&mut self) -> &mut [u8] {
293-
if self.wpos + 128 < self.vec.capacity() {
294-
self.reserve(128);
304+
if self.wpos + 128 > self.vec.len() {
305+
self.vec.resize(self.wpos + 128, 0);
295306
}
296307
&mut self.vec[self.wpos..]
297308
}

0 commit comments

Comments
 (0)