pub struct ScopeGuard<'a> { /* private fields */ }
Expand description
A guard which allows “stashing” ElasticGuard
s for safe loaning.
Bare Elastic::loan
is unsafe, because the returned ElasticGuard
must be dropped. A
ScopeGuard
provided by ScopeArena::scope
allows for collecting ElasticGuard
s 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>
impl<'a> ScopeGuard<'a>
Sourcepub fn loan<T: Stretchable<'a>>(
&mut self,
elastic: &Elastic<T::Stretched>,
value: T,
)
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.