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
impl ChannelData
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of pending elements. Useful for diagnostics; not part of the user-facing method surface.
Sourcepub fn send(&self, slot: KindedSlot) -> Result<(), ()>
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).
Sourcepub fn try_recv(&self) -> Option<KindedSlot>
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.