Struct Scope

Source
pub struct Scope<T>(/* private fields */)
where
    T: ?Sized;
Expand description

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.

Implementations§

Source§

impl<T> Scope<T>
where T: ?Sized,

Source

pub fn scoped<TFn, TRet>(&self, value: &T, fun: TFn) -> TRet
where 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.

Source

pub fn with<TFn, TRet>(&self, fun: TFn) -> TRet
where 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§

Source§

impl<T> Default for Scope<T>
where T: ?Sized,

Creates a new scope without value.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for Scope<T>

§

impl<T> !RefUnwindSafe for Scope<T>

§

impl<T> !Send for Scope<T>

§

impl<T> !Sync for Scope<T>

§

impl<T> Unpin for Scope<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Scope<T>
where T: RefUnwindSafe + ?Sized,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.