pub struct Mailbox<T> { /* private fields */ }Expand description
Collects messages from a channel.
recv and try_recv both take &self, so a mailbox can be held behind a
shared reference and moved between threads. One consumer at a time is still
the rule: a transport whose consumer parks in recv may hold an internal
lock for the duration.
Implementations§
Source§impl<T: Send + 'static> Mailbox<T>
impl<T: Send + 'static> Mailbox<T>
Sourcepub fn of<C: Consume<T> + Send + Sync + 'static>(consumer: C) -> Self
pub fn of<C: Consume<T> + Send + Sync + 'static>(consumer: C) -> Self
Wraps a transport-specific consumer.
Transports build ends through this; everyone else gets them from
Transport::channel.
Sourcepub fn recv(&self) -> Result<T, Disconnected>
pub fn recv(&self) -> Result<T, Disconnected>
Waits for the next message, parking rather than spinning.
Err(Disconnected) means every producer is gone and the queue is
drained — the only unambiguous way for a consumer to learn the channel
is closed.
Sourcepub fn try_recv(&self) -> Option<T>
pub fn try_recv(&self) -> Option<T>
Takes the next message if one is already waiting, without blocking.
The UI thread polls here rather than calling Mailbox::recv, because
it has to keep servicing the event loop between messages.
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Mailbox<T>
impl<T> !UnwindSafe for Mailbox<T>
impl<T> Freeze for Mailbox<T>
impl<T> Send for Mailbox<T>
impl<T> Sync for Mailbox<T>
impl<T> Unpin for Mailbox<T>
impl<T> UnsafeUnpin for Mailbox<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more