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

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.

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.

Take the current value immediately

Resets the internal state on return.

Returns the previous value or None.

Wait for a value and then take it

Resets the internal state on return.

Returns the previous value.

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.

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

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.