Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return impl AsyncBufRead from into_async_read #3164

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ references = ["smithy-rs#3126", "aws-sdk-rust#930"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "rcoh"

[[aws-sdk-rust]]
message = "Change `ByteStream::into_async_read` to return `AsyncBufRead`"
references = ["smithy-rs#3164"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "utkarshgupta137"

[[smithy-rs]]
message = "The HTTP `Request`, `Response`, `Headers`, and `HeaderValue` types have been moved from `aws_smithy_runtime_api::client::http::*` into `aws_smithy_runtime_api::http`"
references = ["smithy-rs#3138"]
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-types/external-types.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ allowed_external_types = [
"hyper::body::body::Body",

# TODO(https://github.com/awslabs/smithy-rs/issues/2412): Support cargo-features for cargo-check-external-types
"tokio::io::async_read::AsyncRead",
"tokio::io::async_buf_read::AsyncBufRead",

# TODO(https://github.com/awslabs/smithy-rs/issues/2412): Support cargo-features for cargo-check-external-types
"tokio::fs::file::File",
Expand Down
17 changes: 8 additions & 9 deletions rust-runtime/aws-smithy-types/src/byte_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,16 @@ pin_project! {
///
/// _Note: The `rt-tokio` feature must be active to use `.into_async_read()`._
///
/// It's possible to convert a `ByteStream` into a struct that implements [`tokio::io::AsyncRead`](tokio::io::AsyncRead).
/// Then, you can use pre-existing tools like [`tokio::io::BufReader`](tokio::io::BufReader):
/// It's possible to convert a `ByteStream` into a struct that implements [`tokio::io::AsyncBufRead`](tokio::io::AsyncBufRead).
/// ```no_run
/// use aws_smithy_types::byte_stream::ByteStream;
/// use aws_smithy_types::body::SdkBody;
/// use tokio::io::{AsyncBufReadExt, BufReader};
/// use tokio::io::AsyncBufReadExt;
/// #[cfg(feature = "rt-tokio")]
/// async fn example() -> std::io::Result<()> {
/// let stream = ByteStream::new(SdkBody::from("hello!\nThis is some data"));
/// // Wrap the stream in a BufReader
/// let buf_reader = BufReader::new(stream.into_async_read());
/// // Convert the stream to a BufReader
/// let buf_reader = stream.into_async_read();
/// let mut lines = buf_reader.lines();
/// assert_eq!(lines.next_line().await?, Some("hello!".to_owned()));
/// assert_eq!(lines.next_line().await?, Some("This is some data".to_owned()));
Expand Down Expand Up @@ -423,23 +422,23 @@ impl ByteStream {
}

#[cfg(feature = "rt-tokio")]
/// Convert this `ByteStream` into a struct that implements [`AsyncRead`](tokio::io::AsyncRead).
/// Convert this `ByteStream` into a struct that implements [`AsyncBufRead`](tokio::io::AsyncBufRead).
///
/// # Example
///
/// ```rust
/// use tokio::io::{BufReader, AsyncBufReadExt};
/// use tokio::io::AsyncBufReadExt;
/// use aws_smithy_types::byte_stream::ByteStream;
///
/// # async fn dox(my_bytestream: ByteStream) -> std::io::Result<()> {
/// let mut lines = BufReader::new(my_bytestream.into_async_read()).lines();
/// let mut lines = my_bytestream.into_async_read().lines();
/// while let Some(line) = lines.next_line().await? {
/// // Do something line by line
/// }
/// # Ok(())
/// # }
/// ```
pub fn into_async_read(self) -> impl tokio::io::AsyncRead {
pub fn into_async_read(self) -> impl tokio::io::AsyncBufRead {
// The `Stream` trait is currently unstable so we can only use it in private.
// Here, we create a local struct just to enable the trait for `ByteStream` and pass it
// to `StreamReader`.
Expand Down
Loading