diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 42e5b69a62..4445a30d0b 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -109,3 +109,31 @@ message = "Add support for constructing [`SdkBody`] and [`ByteStream`] from `htt references = ["smithy-rs#3300", "aws-sdk-rust#977"] meta = { "breaking" = false, "tada" = true, "bug" = false } author = "rcoh" + +[[smithy-rs]] +message = """ Add `PaginationStreamExt` extension trait to `aws-smithy-types-convert` behind the `convert-streams` feature. This makes it possible to treat a paginator as a [`futures_core::Stream`](https://docs.rs/futures-core/latest/futures_core/stream/trait.Stream.html), allowing customers to use stream combinators like [`map`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.map) and [`filter`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.filter). + +Example: + +```rust +use aws_smithy_types_convert::stream::PaginationStreamExt +let stream = s3_client.list_objects_v2().bucket("...").into_paginator().send().into_stream_03x(); +``` +""" +references = ["smithy-rs#3299"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"} +author = "Erlend Langseth " + +[[aws-sdk-rust]] +message = """ Add `PaginationStreamExt` extension trait to `aws-smithy-types-convert` behind the `convert-streams` feature. This makes it possible to treat a paginator as a [`futures_core::Stream`](https://docs.rs/futures-core/latest/futures_core/stream/trait.Stream.html), allowing customers to use stream combinators like [`map`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.map) and [`filter`](https://docs.rs/tokio-stream/latest/tokio_stream/trait.StreamExt.html#method.filter). + +Example: + +```rust +use aws_smithy_types_convert::stream::PaginationStreamExt +let stream = s3_client.list_objects_v2().bucket("...").into_paginator().send().into_stream_03x(); +``` +""" +references = ["smithy-rs#3299"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client"} +author = "Erlend Langseth " diff --git a/rust-runtime/aws-smithy-types-convert/Cargo.toml b/rust-runtime/aws-smithy-types-convert/Cargo.toml index 2bfe50437b..444e48f911 100644 --- a/rust-runtime/aws-smithy-types-convert/Cargo.toml +++ b/rust-runtime/aws-smithy-types-convert/Cargo.toml @@ -10,14 +10,14 @@ repository = "https://github.com/smithy-lang/smithy-rs" [features] convert-chrono = ["aws-smithy-types", "chrono"] convert-time = ["aws-smithy-types", "time"] -convert-streams = ["aws-smithy-async", "tokio-stream"] +convert-streams = ["aws-smithy-async", "futures-core"] [dependencies] aws-smithy-types = { path = "../aws-smithy-types", optional = true } aws-smithy-async = {path = "../aws-smithy-async", optional = true} chrono = { version = "0.4.26", optional = true, default-features = false, features = ["std"] } time = { version = "0.3.4", optional = true } -tokio-stream = { version = "0.1.14", optional = true } +futures-core = { version = "0.3.0", optional = true } [package.metadata.docs.rs] all-features = true diff --git a/rust-runtime/aws-smithy-types-convert/src/stream.rs b/rust-runtime/aws-smithy-types-convert/src/stream.rs index 1ce4ba9dab..3dbf5a789a 100644 --- a/rust-runtime/aws-smithy-types-convert/src/stream.rs +++ b/rust-runtime/aws-smithy-types-convert/src/stream.rs @@ -5,9 +5,9 @@ //! Conversions from Stream-like structs to implementors of `futures::Stream` +use futures_core::Stream; use std::pin::Pin; use std::task::{Context, Poll}; -use tokio_stream::Stream; use aws_smithy_async::future::pagination_stream::PaginationStream; @@ -16,20 +16,14 @@ pub struct PaginationStreamImplStream { pagination_stream: PaginationStream, } -impl PaginationStreamImplStream -where - Item: Send + 'static, -{ +impl PaginationStreamImplStream { /// Create a new Stream object wrapping a `PaginationStream` pub fn new(pagination_stream: PaginationStream) -> Self { PaginationStreamImplStream { pagination_stream } } } -impl Stream for PaginationStreamImplStream -where - Item: Send + 'static, -{ +impl Stream for PaginationStreamImplStream { type Item = Item; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { @@ -40,11 +34,27 @@ where /// Trait to convert PaginationStream into implementor of `Stream` pub trait PaginationStreamExt { /// Convert PaginationStream into implementor of `Stream` - fn as_stream_01x(self) -> PaginationStreamImplStream; + /// + /// # Example + /// ```no_run + /// # use aws_smithy_async::future::pagination_stream::PaginationStream; + /// use aws_smithy_types_convert::stream::PaginationStreamExt; + /// // Assuming you have obtained a pagination stream, by something like: + /// // ``` + /// // let pagination_stream = s3_client + /// // .list_objects_v2() + /// // .bucket(bucket) + /// // .into_paginator() + /// // .send(); + /// // ``` + /// # let pagination_stream: PaginationStream = unimplemented!(); + /// let futures_stream = pagination_stream.into_stream_03x(); + /// ``` + fn into_stream_03x(self) -> PaginationStreamImplStream; } impl PaginationStreamExt for PaginationStream { - fn as_stream_01x(self) -> PaginationStreamImplStream { + fn into_stream_03x(self) -> PaginationStreamImplStream { PaginationStreamImplStream { pagination_stream: self, }