[][src]Struct thread_scoped_ref::Scope

pub struct Scope<T>(_)
where
    T: ?Sized
;

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]

pub fn scoped<TFn, TRet>(&self, value: &T, fun: TFn) -> TRet where
    TFn: FnOnce() -> TRet, 
[src]

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]

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

impl<T> Default for Scope<T> where
    T: ?Sized
[src]

Creates a new scope without value.

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.