Skip to main content

ChannelFactory

Trait ChannelFactory 

Source
pub trait ChannelFactory:
    Clone
    + Send
    + Sync
    + 'static {
    type OneshotSender<T: Send + 'static>: OneshotSend<T>;
    type OneshotReceiver<T: Send + 'static>: OneshotRecv<T>;
    type BoundedSender<T: Send + 'static, const N: usize>: MpscSend<T>;
    type BoundedReceiver<T: Send + 'static, const N: usize>: MpscRecv<T>;
    type UnboundedSender<T: Send + 'static>: UnboundedSend<T>;
    type UnboundedReceiver<T: Send + 'static>: UnboundedRecv<T>;

    // Provided methods
    fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
       where T: OneshotPooled<Self> { ... }
    fn bounded<T, const N: usize>(    ) -> (Self::BoundedSender<T, N>, Self::BoundedReceiver<T, N>)
       where T: BoundedPooled<Self, N> { ... }
    fn unbounded<T>() -> (Self::UnboundedSender<T>, Self::UnboundedReceiver<T>)
       where T: UnboundedPooled<Self> { ... }
}
Expand description

A zero-sized factory that creates channel pairs used by the client’s internal transport.

Abstracting over both tokio::sync::mpsc / oneshot (std path) and embassy-sync::channel::Channel (bare-metal path) behind a single trait lets Client / Inner / SocketManager compile without a tokio dependency when bare_metal is active and tokio is not.

The three channel families:

  • oneshot — single-shot rendezvous, capacity 1. Used for command completion callbacks inside crate::client::ControlMessage.
  • bounded — finite-capacity MPSC queue. Used for the control channel and per-socket send / receive queues.
  • unbounded — notionally unbounded MPSC queue (embassy-sync implementations use a large-capacity channel). Used for the ClientUpdate stream from Inner to Client.

§Per-T opt-in via the *Pooled<Self> traits

The three constructor methods are generic over the channeled type T, but a heap-free static-pool implementation needs to map each T to a pre-declared static storage area. To make that mapping type-safe — and to surface “you forgot to declare a pool for this type” as a compile error rather than a runtime panic — each method requires the channeled type to implement the corresponding *Pooled<Self> trait and delegates the actual construction to it:

fn oneshot<T>() -> (...) where T: OneshotPooled<Self> { T::oneshot_pair() }

Backends that have a single shared allocator (Tokio, embassy-sync) publish a blanket impl<T: Send + 'static> OneshotPooled<Self> for T (and its bounded / unbounded peers), so existing user code does not notice the change. A static-pool backend instead publishes per-T impls (typically generated by a define_static_channels! macro) that wire each T to its declared pool. Calling oneshot::<NotDeclared>() against such a backend fails at the call site with OneshotPooled<MyChannels> is not implemented for NotDeclared.

Required Associated Types§

Source

type OneshotSender<T: Send + 'static>: OneshotSend<T>

Oneshot sender type.

Source

type OneshotReceiver<T: Send + 'static>: OneshotRecv<T>

Oneshot receiver type.

Source

type BoundedSender<T: Send + 'static, const N: usize>: MpscSend<T>

Bounded-channel sender type. The const N: usize parameter is the channel capacity; it must match the N passed to Self::bounded. Backends that store the capacity at construction time (tokio::sync::mpsc) ignore it for storage purposes; backends that bake it into the type (embassy-sync) use it directly.

Source

type BoundedReceiver<T: Send + 'static, const N: usize>: MpscRecv<T>

Bounded-channel receiver type. See Self::BoundedSender.

Source

type UnboundedSender<T: Send + 'static>: UnboundedSend<T>

Unbounded-channel sender type.

Source

type UnboundedReceiver<T: Send + 'static>: UnboundedRecv<T>

Unbounded-channel receiver type.

Provided Methods§

Source

fn oneshot<T>() -> (Self::OneshotSender<T>, Self::OneshotReceiver<T>)
where T: OneshotPooled<Self>,

Create a oneshot channel pair.

Default body delegates to OneshotPooled::oneshot_pair; impls rarely need to override this, they just publish the appropriate OneshotPooled<Self> impls for the types they support.

Source

fn bounded<T, const N: usize>() -> (Self::BoundedSender<T, N>, Self::BoundedReceiver<T, N>)
where T: BoundedPooled<Self, N>,

Create a bounded channel with capacity N.

Default body delegates to BoundedPooled::bounded_pair.

Source

fn unbounded<T>() -> (Self::UnboundedSender<T>, Self::UnboundedReceiver<T>)
where T: UnboundedPooled<Self>,

Create an unbounded channel.

Default body delegates to UnboundedPooled::unbounded_pair.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§