pub struct LocalItem<T> { /* private fields */ }Expand description
A scope-local item.
Implementations§
Source§impl<T: Send + Sync + 'static> LocalItem<T>
impl<T: Send + Sync + 'static> LocalItem<T>
Sourcepub fn with<R>(&self, operation: impl for<'access> FnOnce(&'access T) -> R) -> R
pub fn with<R>(&self, operation: impl for<'access> FnOnce(&'access T) -> R) -> R
Runs operation with the value selected by the active scope.
The higher-ranked closure prevents a reference into per-CPU-selected storage from escaping after preemption is re-enabled. The first global access initializes the global scope before entering the pinned access. Concurrent first access waits for that initialization to be published.
Sourcepub fn with_pinned<R>(
&self,
pin: &CpuPin<'_>,
operation: impl for<'access> FnOnce(&'access T) -> R,
) -> R
pub fn with_pinned<R>( &self, pin: &CpuPin<'_>, operation: impl for<'access> FnOnce(&'access T) -> R, ) -> R
Runs operation under an existing CPU pin without initialization.
§Panics
Panics if the selected global scope has not been initialized by
LocalItem::with. Explicit Scope values are initialized eagerly.
Sourcepub fn try_with_pinned<R>(
&self,
pin: &CpuPin<'_>,
operation: impl for<'access> FnOnce(&'access T) -> R,
) -> Option<R>
pub fn try_with_pinned<R>( &self, pin: &CpuPin<'_>, operation: impl for<'access> FnOnce(&'access T) -> R, ) -> Option<R>
Runs operation without lazy initialization under an existing pin.
This returns None when the selected global scope has not yet been
initialized, allowing hard-IRQ callers to avoid allocation.
Sourcepub fn clone_current(&self) -> Twhere
T: Clone,
pub fn clone_current(&self) -> Twhere
T: Clone,
Clones the selected value while keeping the CPU pin lifetime short.
Sourcepub fn scope<'scope>(&self, scope: &'scope Scope) -> ScopeItem<'scope, T>
pub fn scope<'scope>(&self, scope: &'scope Scope) -> ScopeItem<'scope, T>
Returns a reference to this item within the given scope.
Sourcepub fn scope_mut<'scope>(
&self,
scope: &'scope mut Scope,
) -> ScopeItemMut<'scope, T>
pub fn scope_mut<'scope>( &self, scope: &'scope mut Scope, ) -> ScopeItemMut<'scope, T>
Returns a mutable reference to this item within the given scope.