pub struct StaticMut<T> { /* private fields */ }Expand description
Like StaticCell but provides &mut T access through UnsafeCell.
Used for types that need mutable access from a single owner thread (e.g., DspEngine from audio ISR, IrManager from loader thread).
§Safety contract
init()andshutdown()must be called single-threaded (lifecycle guarantee).get_mut()requires the caller to ensure exclusive access.
Implementations§
Source§impl<T> StaticMut<T>
impl<T> StaticMut<T>
Sourcepub fn try_init(&self, val: T) -> Result<(), T>
pub fn try_init(&self, val: T) -> Result<(), T>
Try to initialize the cell. Returns Err(val) if already initialized,
so the caller doesn’t lose the value.
§Safety contract
Same as init() — must be called single-threaded.
Sourcepub unsafe fn get_mut(&self) -> &mut T
pub unsafe fn get_mut(&self) -> &mut T
Get a mutable reference to the contained value.
§Safety
Caller must ensure exclusive access (single-threaded or external synchronization).
Sourcepub fn try_get(&self) -> Option<&T>
pub fn try_get(&self) -> Option<&T>
Try to get an immutable reference, returning None if not initialized.
Trait Implementations§
impl<T: Send> Send for StaticMut<T>
impl<T: Send> Sync for StaticMut<T>
Auto Trait Implementations§
impl<T> !Freeze for StaticMut<T>
impl<T> !RefUnwindSafe for StaticMut<T>
impl<T> Unpin for StaticMut<T>where
T: Unpin,
impl<T> UnwindSafe for StaticMut<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more