pub struct StaticChannel<T, const CAPACITY: usize, R = DefaultRecycle> { /* private fields */ }
Available on crate feature static only.
Expand description

A statically-allocated, asynchronous bounded MPSC channel.

A statically-allocated channel allows using a MPSC channel without requiring any heap allocations, and can be used in environments that don’t support liballoc.

In order to use a statically-allocated channel, a StaticChannel must be constructed in a static initializer. This reserves storage for the channel’s message queue at compile-time. Then, at runtime, the channel is split into a StaticSender/StaticReceiver pair in order to be used.

Examples

use thingbuf::mpsc::StaticChannel;

// Construct a statically-allocated channel of `usize`s with a capacity
// of 16 messages.
static MY_CHANNEL: StaticChannel<usize, 16> = StaticChannel::new();

fn main() {
    // Split the `StaticChannel` into a sender-receiver pair.
    let (tx, rx) = MY_CHANNEL.split();

    // Now, `tx` and `rx` can be used just like any other async MPSC
    // channel...
}

Implementations

Constructs a new statically-allocated, asynchronous bounded MPSC channel.

A statically-allocated channel allows using a MPSC channel without requiring any heap allocations, and can be used in environments that don’t support liballoc.

In order to use a statically-allocated channel, a StaticChannel must be constructed in a static initializer. This reserves storage for the channel’s message queue at compile-time. Then, at runtime, the channel is split into a StaticSender/StaticReceiver pair in order to be used.

Examples
use thingbuf::mpsc::StaticChannel;

// Construct a statically-allocated channel of `usize`s with a capacity
// of 16 messages.
static MY_CHANNEL: StaticChannel<usize, 16> = StaticChannel::new();

fn main() {
    // Split the `StaticChannel` into a sender-receiver pair.
    let (tx, rx) = MY_CHANNEL.split();

    // Now, `tx` and `rx` can be used just like any other async MPSC
    // channel...
}

Split a StaticChannel into a StaticSender/StaticReceiver pair.

A static channel can only be split a single time. If StaticChannel::split or StaticChannel::try_split have been called previously, this method will panic. For a non-panicking version of this method, see StaticChannel::try_split.

Panics

If the channel has already been split.

Try to split a StaticChannel into a StaticSender/StaticReceiver pair, returning None if it has already been split.

A static channel can only be split a single time. If StaticChannel::split or StaticChannel::try_split have been called previously, this method returns None.

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.