pub struct DiscardOnDrop<A: Discard>(/* private fields */);Expand description
If you have a value which implements Discard, you can use
DiscardOnDrop::new(value) which will wrap the value.
When the wrapper is dropped it will automatically call value.discard().
You can use the leak method to unwrap it (which returns value). This causes
it to no longer call discard when it is dropped, which
means it will usually leak memory unless you manually call discard.
Implementations§
Source§impl<A: Discard> DiscardOnDrop<A>
impl<A: Discard> DiscardOnDrop<A>
Sourcepub fn new(discarder: A) -> Self
pub fn new(discarder: A) -> Self
Creates a new DiscardOnDrop.
When the DiscardOnDrop is dropped it will automatically call discarder.discard().
Sourcepub fn leak(self) -> A
pub fn leak(self) -> A
Returns the wrapped discarder.
It will no longer automatically call discarder.discard(), so this will usually leak
memory unless you manually call discarder.discard().
Trait Implementations§
Source§impl<A: Discard> Deref for DiscardOnDrop<A>
impl<A: Discard> Deref for DiscardOnDrop<A>
Auto Trait Implementations§
impl<A> Freeze for DiscardOnDrop<A>where
A: Freeze,
impl<A> RefUnwindSafe for DiscardOnDrop<A>where
A: RefUnwindSafe,
impl<A> Send for DiscardOnDrop<A>where
A: Send,
impl<A> Sync for DiscardOnDrop<A>where
A: Sync,
impl<A> Unpin for DiscardOnDrop<A>where
A: Unpin,
impl<A> UnwindSafe for DiscardOnDrop<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more