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§

source§

impl<T, const CAPACITY: usize> StaticChannel<T, CAPACITY>

source

pub const fn new() -> Self

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...
}
source§

impl<T, R, const CAPACITY: usize> StaticChannel<T, CAPACITY, R>

source

pub fn split(&'static self) -> (StaticSender<T, R>, StaticReceiver<T, R>)

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.

source

pub fn try_split( &'static self ) -> Option<(StaticSender<T, R>, StaticReceiver<T, R>)>

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§

§

impl<T, const CAPACITY: usize, R = DefaultRecycle> !RefUnwindSafe for StaticChannel<T, CAPACITY, R>

§

impl<T, const CAPACITY: usize, R> Send for StaticChannel<T, CAPACITY, R>where R: Send, T: Send,

§

impl<T, const CAPACITY: usize, R> Sync for StaticChannel<T, CAPACITY, R>where R: Sync, T: Sync,

§

impl<T, const CAPACITY: usize, R> Unpin for StaticChannel<T, CAPACITY, R>where R: Unpin, T: Unpin,

§

impl<T, const CAPACITY: usize, R = DefaultRecycle> !UnwindSafe for StaticChannel<T, CAPACITY, R>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.