pub struct Relay<T> { /* private fields */ }Expand description
Move single values between threads
A condition variable with a single slot that allows to pass values from producer to consumer threads. Producers and consumers may arrive at any point in time.
A typical scenario involves only a single producer and a single consumer thread implementing a handover protocol for passing the latest (= most recent) value between each other.
The value is buffered until the consumer is ready to take it. Each value can be consumed at most once. Producers can replace the current value if it has not been consumed yet.
Implementations
sourceimpl<T> Relay<T>
impl<T> Relay<T>
pub const fn new() -> Self
pub const fn with_value(value: T) -> Self
sourceimpl<T> Relay<T>
impl<T> Relay<T>
sourcepub fn replace_notify_one(&self, value: T) -> Option<T>
pub fn replace_notify_one(&self, value: T) -> Option<T>
Replace the current value and notify a single waiting consumer
Returns the previous value or None. If None is returned
then a notification has been triggered.
sourcepub fn replace_notify_all(&self, value: T) -> Option<T>
pub fn replace_notify_all(&self, value: T) -> Option<T>
Replace the current value and notify all waiting consumers
Returns the previous value or None. If None is returned
then a notification has been triggered.
sourcepub fn take(&self) -> Option<T>
pub fn take(&self) -> Option<T>
Take the current value immediately
Resets the internal state on return.
Returns the previous value or None.
sourcepub fn wait(&self) -> T
pub fn wait(&self) -> T
Wait for a value and then take it
Resets the internal state on return.
Returns the previous value.
sourcepub fn wait_for(&self, timeout: Duration) -> Option<T>
pub fn wait_for(&self, timeout: Duration) -> Option<T>
Wait for a value with a timeout and then take it
Resets the internal state on return, i.e. either takes the value
or on timeout the internal value already was None and doesn’t
need to be reset.
Returns the value if available or None if the timeout expired.
sourcepub fn wait_until(&self, deadline: Instant) -> Option<T>
pub fn wait_until(&self, deadline: Instant) -> Option<T>
Wait for a value until a deadline and then take it
Resets the internal state on return, i.e. either takes the value
or on timeout the internal value already was None and doesn’t
need to be reset.
Returns the value if available or None if the deadline expired.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Relay<T>
impl<T> Send for Relay<T> where
T: Send,
impl<T> Sync for Relay<T> where
T: Send,
impl<T> Unpin for Relay<T> where
T: Unpin,
impl<T> UnwindSafe for Relay<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more