Skip to main content

ChannelData

Struct ChannelData 

Source
pub struct ChannelData { /* private fields */ }
Expand description

MPSC-style synchronous channel storage.

ADR-006 §2.7.20 / Q21 amendment (Wave 15 W15-channel-rebuild, 2026-05-10). Channel is a concurrency primitive; unlike the HashMap/HashSet siblings (insertion-ordered immutable-on-clone keys-buffer with Arc::make_mut clone-on-write), Channel needs interior mutability so that two Arc<ChannelData> shares of the same channel observe each other’s send / recv mutations (the producer and consumer endpoints share the same buffer). The inner state therefore lives behind a Mutex<ChannelInner>; the outer Arc is purely a refcount carrier.

Sync same-thread path only at landing. Cross-task / cross- thread blocking recv() (the canonical async-channel use case) requires integration with the §2.7.4 task-scheduler boundary (shape-vm/src/executor/task_scheduler.rs), which is itself a phase-2c surface; per the W15 playbook the async paths SURFACE cleanly. The sync path (same-thread send then recv) lands here end-to-end.

Element typing. The buffer stores KindedSlot payloads directly so heterogeneous-element queues are first-class (a channel can carry ints, strings, or typed objects without a per-element-kind specialisation). Each slot owns one strong- count share for heap-bearing kinds; the KindedSlot::Drop dispatch retires shares cleanly when the channel itself drops. This is the same shape concurrency_methods.rs (Mutex/Atomic/ Lazy) will use when those primitives rebuild — Channel is the first concurrency primitive to land kinded.

Closed flag. closed: bool records whether the producer side has signalled end-of-stream. After close() further send() calls return a closed-channel error; recv() continues to drain queued elements and only errors once the queue is empty (canonical drain-on-close semantics).

Implementations§

Source§

impl ChannelData

Source

pub fn new() -> Self

Build an empty open channel.

Source

pub fn len(&self) -> usize

Number of pending elements. Useful for diagnostics; not part of the user-facing method surface.

Source

pub fn is_empty(&self) -> bool

Whether the queue currently holds zero pending elements.

Source

pub fn is_closed(&self) -> bool

Whether close() has been called.

Source

pub fn send(&self, slot: KindedSlot) -> Result<(), ()>

Append slot to the queue.

Returns Ok(()) on success, Err(()) if the channel is already closed (callers surface this as a runtime error from the send method body).

Source

pub fn try_recv(&self) -> Option<KindedSlot>

Pop the front element non-blocking.

Returns Some(slot) if an element was available, None otherwise. Per ADR §2.7.20 the same-thread sync path is the supported surface; blocking recv() (await-style) requires the §2.7.4 task-scheduler boundary and is SURFACE’d at the method body.

Source

pub fn close(&self)

Mark the channel closed. Idempotent — calling close on an already-closed channel is a no-op.

Trait Implementations§

Source§

impl Debug for ChannelData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ChannelData

Source§

fn default() -> Self

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

Auto Trait Implementations§

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, 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.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,