Struct aws_smithy_async::future::pagination_stream::fn_stream::FnStream
source · pub struct FnStream<Item> { /* private fields */ }
Expand description
The closure is passed a reference to a Sender
which acts as a rendezvous channel. Messages
sent to the sender will be emitted to the stream. Because the stream is 1-bounded, the function
will not proceed until the stream is read.
This utility is used by generated paginators to generate a stream of paginated results.
If tx.send
returns an error, the function MUST return immediately.
Note FnStream
is only Send
but not Sync
because generator
is a boxed future that
is Send
and returns ()
as output when it is done.
§Examples
use aws_smithy_async::future::pagination_stream::fn_stream::FnStream;
let mut stream = FnStream::new(|tx| Box::pin(async move {
if let Err(_) = tx.send("Hello!").await {
return;
}
if let Err(_) = tx.send("Goodbye!").await {
return;
}
}));
assert_eq!(stream.collect::<Vec<_>>().await, vec!["Hello!", "Goodbye!"]);
Implementations§
Trait Implementations§
impl<'__pin, Item> Unpin for FnStream<Item>where
PinnedFieldsOf<__Origin<'__pin, Item>>: Unpin,
Auto Trait Implementations§
impl<Item> Freeze for FnStream<Item>
impl<Item> !RefUnwindSafe for FnStream<Item>
impl<Item> Send for FnStream<Item>where
Item: Send,
impl<Item> !Sync for FnStream<Item>
impl<Item> !UnwindSafe for FnStream<Item>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more