From a20889a2785d58de50607a795fda6ed6b20b1cab Mon Sep 17 00:00:00 2001 From: Parker Timmerman <126496446+parker-timmerman@users.noreply.github.com> Date: Fri, 31 Mar 2023 17:26:19 -0400 Subject: [PATCH] runtime: add a method `into_segments` to `AggregatedBytes` (#2525) * start, add a method to AggregatedBytes called into_segments * update CHANGELOG.next.toml --- CHANGELOG.next.toml | 6 ++++++ rust-runtime/aws-smithy-http/src/byte_stream.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index b1d81d9794..7770e39605 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -74,3 +74,9 @@ message = "Add support for omitting session token in canonical requests for SigV references = ["smithy-rs#2473"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "martinjlowm" + +[[aws-sdk-rust]] +message = "Add `into_segments` method to `AggregatedBytes`, for zero-copy conversions." +references = ["smithy-rs#2525"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "parker-timmerman" diff --git a/rust-runtime/aws-smithy-http/src/byte_stream.rs b/rust-runtime/aws-smithy-http/src/byte_stream.rs index 3b99c0a68d..fcd697c7b4 100644 --- a/rust-runtime/aws-smithy-http/src/byte_stream.rs +++ b/rust-runtime/aws-smithy-http/src/byte_stream.rs @@ -477,6 +477,11 @@ impl AggregatedBytes { self.0.copy_to_bytes(self.0.remaining()) } + /// Convert this buffer into an [`Iterator`] of underlying non-contiguous segments of [`Bytes`] + pub fn into_segments(self) -> impl Iterator { + self.0.into_inner().into_iter() + } + /// Convert this buffer into a `Vec` pub fn to_vec(self) -> Vec { self.0