-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stream implementation (wrapper) for PaginationStream (#3299)
## Motivation and Context awslabs/aws-sdk-rust#995 ## Description I tried to implement futures::Stream for a wrapper struct around `PaginationStream`. I am unsure if I did it in the best way. After fighting with the borrow checker for a while I decided to try `Arc<Mutex<_>>` - is this the way to go or does there exist a better way? Even then, does the code look correct? I used it in my project and my integration tests do pass but I am not 100% that these tests will catch any error in paginated ListObjectsV2. I would appreciate any feedback so far. ## Testing In progress while waiting for feedback on code ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: Russell Cohen <[email protected]> Co-authored-by: Russell Cohen <[email protected]>
- Loading branch information
1 parent
3ea5992
commit 7541fe7
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
//! Conversions from Stream-like structs to implementors of `futures::Stream` | ||
|
||
use futures_core::Stream; | ||
use std::pin::Pin; | ||
use std::task::{Context, Poll}; | ||
|
||
use aws_smithy_async::future::pagination_stream::PaginationStream; | ||
|
||
/// Stream implementor wrapping `PaginationStream` | ||
pub struct PaginationStreamImplStream<Item> { | ||
pagination_stream: PaginationStream<Item>, | ||
} | ||
|
||
impl<Item> PaginationStreamImplStream<Item> { | ||
/// Create a new Stream object wrapping a `PaginationStream` | ||
pub fn new(pagination_stream: PaginationStream<Item>) -> Self { | ||
PaginationStreamImplStream { pagination_stream } | ||
} | ||
} | ||
|
||
impl<Item> Stream for PaginationStreamImplStream<Item> { | ||
type Item = Item; | ||
|
||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { | ||
self.pagination_stream.poll_next(cx) | ||
} | ||
} | ||
|
||
/// Trait to convert PaginationStream into implementor of `Stream` | ||
pub trait PaginationStreamExt<Item> { | ||
/// Convert PaginationStream into implementor of `Stream` | ||
/// | ||
/// # 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<i32> = unimplemented!(); | ||
/// let futures_stream = pagination_stream.into_stream_03x(); | ||
/// ``` | ||
fn into_stream_03x(self) -> PaginationStreamImplStream<Item>; | ||
} | ||
|
||
impl<Item> PaginationStreamExt<Item> for PaginationStream<Item> { | ||
fn into_stream_03x(self) -> PaginationStreamImplStream<Item> { | ||
PaginationStreamImplStream { | ||
pagination_stream: self, | ||
} | ||
} | ||
} |