Struct DropGuard
pub struct DropGuard<T, F>
where
F: FnOnce(T), { pub(in ::mem::drop_guard) inner: ManuallyDrop<T>, pub(in ::mem::drop_guard) f: ManuallyDrop<F> }
Wrap a value and run a closure when dropped.
This is useful for quickly creating destructors inline.
Examples
#
use DropGuard;
Fields
inner: ManuallyDrop<T>f: ManuallyDrop<F>
Implementations
impl<T, F> DropGuard<T, F>
where
F: FnOnce(T),
const fn new(inner: T, f: F) -> SelfCreate a new instance of
DropGuard.Example
# use DropGuard; let value = Stringfrom; let guard = new;const fn dismiss(guard: Self) -> T where F: ,Consumes the
DropGuard, returning the wrapped value.This will not execute the closure. It is typically preferred to call this function instead of
mem::forgetbecause it will return the stored value and drop variables captured by the closure instead of leaking their owned resources.Example
# use DropGuard; let value = Stringfrom; let guard = new; assert_eq!;
Trait Implementations
impl<T, F> Debug for DropGuard<T, F>
where
T: Debug,
F: FnOnce(T),
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<T, F> Deref for DropGuard<T, F>
where
F: FnOnce(T),
type Target = T;fn deref(&self) -> &T
impl<T, F> DerefMut for DropGuard<T, F>
where
F: FnOnce(T),
fn deref_mut(&mut self) -> &mut T
impl<T, F> Drop for DropGuard<T, F>
where
F: ~const FnOnce(T),
fn drop(&mut self)
Auto Trait Implementations
impl<T, F> Freeze for DropGuard<T, F>
where
ManuallyDrop<T>: Freeze,
ManuallyDrop<F>: Freeze,
impl<T, F> RefUnwindSafe for DropGuard<T, F>
where
ManuallyDrop<T>: RefUnwindSafe,
ManuallyDrop<F>: RefUnwindSafe,
impl<T, F> Send for DropGuard<T, F>
where
ManuallyDrop<T>: Send,
ManuallyDrop<F>: Send,
impl<T, F> Sync for DropGuard<T, F>
where
ManuallyDrop<T>: Sync,
ManuallyDrop<F>: Sync,
impl<T, F> Unpin for DropGuard<T, F>
where
ManuallyDrop<T>: Unpin,
ManuallyDrop<F>: Unpin,
impl<T, F> UnsafeUnpin for DropGuard<T, F>
where
ManuallyDrop<T>: UnsafeUnpin,
ManuallyDrop<F>: UnsafeUnpin,
impl<T, F> UnwindSafe for DropGuard<T, F>
where
ManuallyDrop<T>: UnwindSafe,
ManuallyDrop<F>: UnwindSafe,
Blanket Implementations
impl<P, T> Receiver for DropGuard<T, F>
where
P: Deref<Target = T> + ?Sized,
T: ?Sized,
type Target = T;
impl<T> Any for DropGuard<T, F>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for DropGuard<T, F>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for DropGuard<T, F>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for DropGuard<T, F>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for DropGuard<T, F>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for DropGuard<T, F>
impl<T, U> Into<U> for DropGuard<T, F>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for DropGuard<T, F>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for DropGuard<T, F>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>