expression
Model exclusive peripheral acquisition
A device PAC commonly offers a unique acquisition API for peripheral tokens. Ownership helps avoid simultaneous mutable use. This no_std model guarantees one token per Pool value only; Pool::new creates a new independent simulated pool. It is not a process-wide hardware singleton and must not be used to wrap real registers. Expected host stdout (not executed): first: true second: false Common mistake: Assuming Option::take by itself enforces uniqueness across independently created pools or cores.
Formal Syntax & Structure
rust syntaxrust
Option<T>::take() -> Option<T>Working Example
Example Snippetrust
#![no_std]pub struct PinToken { _private: () }pub struct Pool(Option<PinToken>);impl Pool { pub const fn new() -> Self { Self(Some(PinToken { _private: () })) } pub fn take(&mut self) -> Option<PinToken> { self.0.take() }}