pub struct ReceiverStream<T> { /* private fields */ }Expand description
A wrapper around tokio::sync::mpsc::Receiver that implements Stream.
§Example
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;
let (tx, rx) = mpsc::channel(2);
tx.send(10).await?;
tx.send(20).await?;
drop(tx);
let mut stream = ReceiverStream::new(rx);
assert_eq!(stream.next().await, Some(10));
assert_eq!(stream.next().await, Some(20));
assert_eq!(stream.next().await, None);Implementations§
Source§impl<T> ReceiverStream<T>
impl<T> ReceiverStream<T>
Sourcepub fn into_inner(self) -> Receiver<T>
pub fn into_inner(self) -> Receiver<T>
Get back the inner Receiver.
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Closes the receiving half of a channel without dropping it.
This prevents any further messages from being sent on the channel while
still enabling the receiver to drain messages that are buffered. Any
outstanding Permit values will still be able to send messages.
To guarantee no messages are dropped, after calling close(), you must
receive all items from the stream until None is returned.
Trait Implementations§
Source§impl<T> AsMut<Receiver<T>> for ReceiverStream<T>
impl<T> AsMut<Receiver<T>> for ReceiverStream<T>
Source§impl<T> AsRef<Receiver<T>> for ReceiverStream<T>
impl<T> AsRef<Receiver<T>> for ReceiverStream<T>
Source§impl<T: Debug> Debug for ReceiverStream<T>
impl<T: Debug> Debug for ReceiverStream<T>
Source§impl<T> From<Receiver<T>> for ReceiverStream<T>
impl<T> From<Receiver<T>> for ReceiverStream<T>
Source§impl<T> Stream for ReceiverStream<T>
impl<T> Stream for ReceiverStream<T>
Source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns the bounds of the stream based on the underlying receiver.
For open channels, it returns (receiver.len(), None).
For closed channels, it returns (receiver.len(), Some(used_capacity))
where used_capacity is calculated as receiver.max_capacity() - receiver.capacity(). This accounts for any Permit that is still
able to send a message.
Auto Trait Implementations§
impl<T> Freeze for ReceiverStream<T>
impl<T> RefUnwindSafe for ReceiverStream<T>
impl<T> Send for ReceiverStream<T>where
T: Send,
impl<T> Sync for ReceiverStream<T>where
T: Send,
impl<T> Unpin for ReceiverStream<T>
impl<T> UnwindSafe for ReceiverStream<T>
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
Source§impl<St> StreamExt for St
impl<St> StreamExt for St
Source§fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
fn next(&mut self) -> Next<'_, Self>where
Self: Unpin,
None if the
stream is finished. Read moreSource§fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
fn try_next<T, E>(&mut self) -> TryNext<'_, Self>
Source§fn map<T, F>(self, f: F) -> Map<Self, F>
fn map<T, F>(self, f: F) -> Map<Self, F>
Source§fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
fn map_while<T, F>(self, f: F) -> MapWhile<Self, F>
None. Read moreSource§fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
fn then<F, Fut>(self, f: F) -> Then<Self, Fut, F>
Source§fn merge<U>(self, other: U) -> Merge<Self, U>
fn merge<U>(self, other: U) -> Merge<Self, U>
Source§fn filter<F>(self, f: F) -> Filter<Self, F>
fn filter<F>(self, f: F) -> Filter<Self, F>
Source§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
None. Read moreSource§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where
Self: Sized,
n items of the underlying stream. Read moreSource§fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
fn take_while<F>(self, f: F) -> TakeWhile<Self, F>
true. Read moreSource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
n first items of the
underlying stream. Read moreSource§fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
fn skip_while<F>(self, f: F) -> SkipWhile<Self, F>
true. Read moreSource§fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F>
fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F>
Source§fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F>
fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F>
Source§fn chain<U>(self, other: U) -> Chain<Self, U>
fn chain<U>(self, other: U) -> Chain<Self, U>
Source§fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, B, F>
fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, B, F>
Source§fn collect<T>(self) -> Collect<Self, T, T::InternalCollection>
fn collect<T>(self) -> Collect<Self, T, T::InternalCollection>
Source§fn timeout(self, duration: Duration) -> Timeout<Self>where
Self: Sized,
fn timeout(self, duration: Duration) -> Timeout<Self>where
Self: Sized,
time only.Source§fn timeout_repeating(self, interval: Interval) -> TimeoutRepeating<Self>where
Self: Sized,
fn timeout_repeating(self, interval: Interval) -> TimeoutRepeating<Self>where
Self: Sized,
time only.Source§fn throttle(self, duration: Duration) -> Throttle<Self>where
Self: Sized,
fn throttle(self, duration: Duration) -> Throttle<Self>where
Self: Sized,
time only.Source§fn chunks_timeout(
self,
max_size: usize,
duration: Duration,
) -> ChunksTimeout<Self>where
Self: Sized,
fn chunks_timeout(
self,
max_size: usize,
duration: Duration,
) -> ChunksTimeout<Self>where
Self: Sized,
time only.