pub struct LocalKey<T: 'static> { /* private fields */ }Expand description
A task-local key, declared with task_local!.
Implementations§
Source§impl<T: 'static> LocalKey<T>
impl<T: 'static> LocalKey<T>
Sourcepub fn scope<F: Future>(
&'static self,
value: T,
future: F,
) -> TaskLocalFuture<T, F> ⓘ
pub fn scope<F: Future>( &'static self, value: T, future: F, ) -> TaskLocalFuture<T, F> ⓘ
A future that runs future with the key set to value in each of its
polls, and drops future (when it is dropped early) with the value
still set.
Sourcepub fn sync_scope<F: FnOnce() -> R, R>(&'static self, value: T, f: F) -> R
pub fn sync_scope<F: FnOnce() -> R, R>(&'static self, value: T, f: F) -> R
Runs f with the key set to value, then unsets it.
Sourcepub fn with<F: FnOnce(&T) -> R, R>(&'static self, f: F) -> R
pub fn with<F: FnOnce(&T) -> R, R>(&'static self, f: F) -> R
Runs f on the key’s value.
§Panics
Where no scope set the key; try_with answers an
AccessError instead.
Sourcepub fn try_with<F: FnOnce(&T) -> R, R>(
&'static self,
f: F,
) -> Result<R, AccessError>
pub fn try_with<F: FnOnce(&T) -> R, R>( &'static self, f: F, ) -> Result<R, AccessError>
Runs f on the key’s value, or answers an AccessError where no
scope set it.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for LocalKey<T>
impl<T> RefUnwindSafe for LocalKey<T>
impl<T> Send for LocalKey<T>
impl<T> Sync for LocalKey<T>
impl<T> Unpin for LocalKey<T>
impl<T> UnsafeUnpin for LocalKey<T>
impl<T> UnwindSafe for LocalKey<T>
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