From 812c52070a2791c2016b7fe7fc4e54fb83c7b381 Mon Sep 17 00:00:00 2001 From: Pure White Date: Mon, 30 Jun 2025 12:39:17 +0800 Subject: [PATCH 1/2] feat: support ioslice --- Cargo.toml | 2 +- src/lib.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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..9596060 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,6 +103,19 @@ 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)); + } + ioslice.push(IoSlice::new(self.bytes.as_ref())); + ioslice + } + // TODO: use write_all_vectored when stable pub async fn write_all_vectored( &mut self, From f04fb6b5287704bb0810960940c8e6a52c87b29c Mon Sep 17 00:00:00 2001 From: Pure White Date: Mon, 30 Jun 2025 12:41:37 +0800 Subject: [PATCH 2/2] Update src/lib.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 9596060..18893b9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,7 +112,9 @@ impl LinkedBytes { } ioslice.push(IoSlice::new(bytes)); } - ioslice.push(IoSlice::new(self.bytes.as_ref())); + if !self.bytes.is_empty() { + ioslice.push(IoSlice::new(self.bytes.as_ref())); + } ioslice }