pub struct ResourceSlot<T> { /* private fields */ }Expand description
A one-value handoff cell threading an owned resource from main into a
supervised task — the safe replacement for Peripherals::steal() inside
the task body.
Declared (as a pub static) by supervisor_graph! for each entry in a
node’s resources: clause. The protocol:
mainsplitsPeripheralsand moves the resource in withprovide. This is where the compile-time guarantee lives: the singleton field is consumed, so no second owner — and nounsafesteal — can exist.- The generated spawn glue
takes it just before spawning the node. An empty slot fails the spawn withSpawnError::Busy— a fail-closed error out ofSupervisor::start, not a panic inside the task (comparestatic_cell::StaticCell, which panics on misuse). - The generated task shell hands the worker
&mut Tandrestores the value after the worker returns, so aTerminaterespawn re-takes the same instance instead of stealing a fresh one. (APauseworker never returns — it parks — so it simply retains the resource, exactly like a hand-written parked task.)
Same primitives as SpawnerSlot: a critical-section
BlockingMutex<Cell<Option<T>>> for the value (Sync for
T: Send, provided by embassy-sync — no unsafe here) plus a latching
Signal so the supervisor can await late provisioning (bounded; see
Supervisor::start).
Implementations§
Source§impl<T> ResourceSlot<T>
impl<T> ResourceSlot<T>
Sourcepub fn provide(&self, value: T)
pub fn provide(&self, value: T)
Move the resource in (from main’s Peripherals split) and wake the
supervisor’s pre-spawn wait. Call before Supervisor::start; a slot
still empty after the supervisor’s bounded wait fails that node’s spawn
with SpawnError::Busy. Filling an occupied slot replaces (drops) the
old value — don’t: one resource, one slot, moved exactly once.
Sourcepub fn take(&self) -> Option<T>
pub fn take(&self) -> Option<T>
Take the resource out, leaving the slot empty. Called by the generated
spawn glue just before the spawn; None means “not provided yet” or
“currently held by a live task instance”.
Sourcepub fn get(&self) -> Option<T>where
T: Copy,
pub fn get(&self) -> Option<T>where
T: Copy,
Copy the resource out without emptying the slot — the shared
resource kind’s read: any number of consumers (several nodes, a whole
pool) get the same Copy handle, and the slot stays filled for the
next one. Only for T: Copy (a Stack-like handle, a &'static
registry ref); an owned singleton uses take.
Trait Implementations§
Source§impl<T> Default for ResourceSlot<T>
impl<T> Default for ResourceSlot<T>
Source§impl<T: Send> ResourceGate for ResourceSlot<T>
impl<T: Send> ResourceGate for ResourceSlot<T>
Source§fn filled_signal(&self) -> &Signal<CriticalSectionRawMutex, ()>
fn filled_signal(&self) -> &Signal<CriticalSectionRawMutex, ()>
Signal fired by provide/restore, for the supervisor’s
bounded pre-spawn wait (see Supervisor::start).