1 // Extracted from the scopeguard crate
2 use core
::ops
::{Deref, DerefMut}
;
4 pub struct ScopeGuard
<T
, F
>
12 #[cfg_attr(feature = "inline-more", inline)]
13 pub fn guard
<T
, F
>(value
: T
, dropfn
: F
) -> ScopeGuard
<T
, F
>
17 ScopeGuard { dropfn, value }
20 impl<T
, F
> Deref
for ScopeGuard
<T
, F
>
25 #[cfg_attr(feature = "inline-more", inline)]
26 fn deref(&self) -> &T
{
31 impl<T
, F
> DerefMut
for ScopeGuard
<T
, F
>
35 #[cfg_attr(feature = "inline-more", inline)]
36 fn deref_mut(&mut self) -> &mut T
{
41 impl<T
, F
> Drop
for ScopeGuard
<T
, F
>
45 #[cfg_attr(feature = "inline-more", inline)]
47 (self.dropfn
)(&mut self.value
)