Skip to main content

Channel

Struct Channel 

Source
pub struct Channel<D, T, Tr, C: CodecFor<T>> { /* private fields */ }
Expand description

A typed, directed communication endpoint over a transport half.

§Type parameters

§Buffer ownership

Channel does not allocate. The caller provides a &'static mut [u8] scratch buffer at construction. In no_std environments this is typically a static array — see consortium_runtime_mcu::static_buf! for a helper that takes the raw static mut out of application code:

use consortium_codec::PostcardCodec;
use consortium_ipc::{Channel, Tx};

static mut BUF: [u8; 256] = [0u8; 256];

// Taking the one and only reference to BUF.
let buf = unsafe { &mut *core::ptr::addr_of_mut!(BUF) };
let ch = Channel::<Tx, MyMsg, _, PostcardCodec>::new(chan, transport, buf);

The buffer must be at least transport.max_send_size() / max_recv_size() bytes.

Implementations§

Source§

impl<D, T, Tr, C: CodecFor<T>> Channel<D, T, Tr, C>

Source

pub fn new(chan: Chan, transport: Tr, buf: &'static mut [u8]) -> Self

Construct a Channel.

chan - validated channel identifier transport - initialised transport half buf - scratch buffer, sized for the transport MTU

Source

pub fn chan(&self) -> Chan

The Chan this endpoint is bound to.

Source§

impl<T, Tr, C> Channel<Tx, T, Tr, C>
where Tr: SendTransport, C: CodecFor<T>,

Source

pub async fn send(&mut self, msg: &T) -> Result<(), ChannelError<C, Tr>>

Encode msg with the codec and hand the bytes to the transport.

The transport rings the doorbell internally.
Returns when bytes are handed off - not when the remote has processed them.

Source§

impl<T, Tr, C> Channel<Rx, T, Tr, C>
where Tr: RecvTransport, C: CodecFor<T>,

Source

pub async fn recv( &mut self, ) -> Result<ReceivedMessage<'_, T, C>, ChannelError<C, Tr>>

Await the next message from the transport and decode it.

Blocks until the transport’s doorbell fires and bytes arrive.
Returns a ReceivedMessage wrapping the decoded value.

When C = PostcardCodec the message is an owned T.
When C is a future zero-copy codec the returned handle will borrow the internal buffer - the '_ lifetime on ReceivedMessage already accommodates this without any change to this signature.

Auto Trait Implementations§

§

impl<D, T, Tr, C> !UnwindSafe for Channel<D, T, Tr, C>

§

impl<D, T, Tr, C> Freeze for Channel<D, T, Tr, C>
where Tr: Freeze,

§

impl<D, T, Tr, C> RefUnwindSafe for Channel<D, T, Tr, C>

§

impl<D, T, Tr, C> Send for Channel<D, T, Tr, C>
where Tr: Send, D: Send, T: Send, C: Send,

§

impl<D, T, Tr, C> Sync for Channel<D, T, Tr, C>
where Tr: Sync, D: Sync, T: Sync, C: Sync,

§

impl<D, T, Tr, C> Unpin for Channel<D, T, Tr, C>
where Tr: Unpin, D: Unpin, T: Unpin, C: Unpin,

§

impl<D, T, Tr, C> UnsafeUnpin for Channel<D, T, Tr, C>
where Tr: UnsafeUnpin,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> MaybeSend for T

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.