diff --git a/Cargo.toml b/Cargo.toml index 194594a..1939f53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "linkedbytes" -version = "0.1.9" +version = "0.1.10" authors = ["Volo Team "] edition = "2021" description = "LinkedBytes is a linked list of Bytes and BytesMut." diff --git a/src/lib.rs b/src/lib.rs index 194e71a..fb455f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,6 +73,18 @@ impl LinkedBytes { self.bytes.reserve(additional); } + pub fn len(&self) -> usize { + let mut len = 0; + for node in self.list.iter() { + len += node.as_ref().len(); + } + len + self.bytes.len() + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } + pub fn insert(&mut self, bytes: Bytes) { let node = Node::Bytes(bytes); // split current bytes