Struct ScopeGuard

Source
pub struct ScopeGuard<'a> { /* private fields */ }
Expand description

A guard which allows “stashing” ElasticGuards for safe loaning.

Bare Elastic::loan is unsafe, because the returned ElasticGuard must be dropped. A ScopeGuard provided by ScopeArena::scope allows for collecting ElasticGuards through its safe ScopeGuard::loan method, because the ScopeArena ensures that all loans are ended at the end of the scope.

As an aside, ScopeGuard is an excellent example of a type which cannot be safely stretched: the lifetime parameter of the ScopeGuard corresponds to the accepted lifetime on the type parameter of ScopeGuard::loan. As a result, effectively, ScopeGuard has the variance of fn(&'a mut ...); it is safe to lengthen the lifetimes fed to ScopeGuard, but absolutely not safe to shorten them!

Implementations§

Source§

impl<'a> ScopeGuard<'a>

Source

pub fn loan<T: Stretchable<'a>>( &mut self, elastic: &Elastic<T::Stretched>, value: T, )

Loan to an elastic within the lifetime of the scope guard.

Trait Implementations§

Source§

impl<'a> Debug for ScopeGuard<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ScopeGuard<'a>

§

impl<'a> !RefUnwindSafe for ScopeGuard<'a>

§

impl<'a> !Send for ScopeGuard<'a>

§

impl<'a> !Sync for ScopeGuard<'a>

§

impl<'a> Unpin for ScopeGuard<'a>

§

impl<'a> !UnwindSafe for ScopeGuard<'a>

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.