[−][src]Struct thread_scoped_ref::Scope
A scope. There's usually one scope per thread.
Note: Usually you don't use this directly. See thread_scoped_ref
(with example)
and with
/ scoped
.
Safety
This struct uses unsafe functionality. When calling the scope
function a reference to the
value is kept as long as the scope
function is running. The reference to the value
is removed when the scope function ends. To make sure the reference is removed even in the
case of a panic, there's a cleanup struct that performs cleanup when dropped.
Methods
impl<T> Scope<T> where
T: ?Sized,
[src]
T: ?Sized,
pub fn scoped<TFn, TRet>(&self, value: &T, fun: TFn) -> TRet where
TFn: FnOnce() -> TRet,
[src]
TFn: FnOnce() -> TRet,
Run the given function scoped with given value reference.
Note: Panicking within the function should be ok, the scope is cleaned up properly.
pub fn with<TFn, TRet>(&self, fun: TFn) -> TRet where
TFn: FnOnce(Option<&T>) -> TRet,
[src]
TFn: FnOnce(Option<&T>) -> TRet,
Runs the given function with the value from the scope (if there's any). If you're not
inside a scope, there won't be a value (function will receive None
).
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Scope<T>
impl<T> !Send for Scope<T>
impl<T> !Sync for Scope<T>
impl<T: ?Sized> Unpin for Scope<T>
impl<T: ?Sized> UnwindSafe for Scope<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,