diff --git a/Cargo.toml b/Cargo.toml index 1939f53..c03f12e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "linkedbytes" -version = "0.1.10" +version = "0.1.11" 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 fb455f4..18893b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,21 @@ impl LinkedBytes { self.list.push_back(node); } + pub fn io_slice(&mut self) -> Vec> { + let mut ioslice = Vec::with_capacity(self.list.len() + 1); + for node in self.list.iter() { + let bytes = node.as_ref(); + if bytes.is_empty() { + continue; + } + ioslice.push(IoSlice::new(bytes)); + } + if !self.bytes.is_empty() { + ioslice.push(IoSlice::new(self.bytes.as_ref())); + } + ioslice + } + // TODO: use write_all_vectored when stable pub async fn write_all_vectored( &mut self,