Struct discard::DiscardOnDrop [−][src]
#[must_use = "\nThe DiscardOnDrop is unused, which causes it to be immediately discarded.\nYou probably don\'t want that to happen.\n\nHow to fix this:\n\n * Store the DiscardOnDrop in a variable or data structure.\n\n * Or use the DiscardOnDrop::leak function which will cause it to not be\n discarded (this *will* leak memory!).\n\nSee the DiscardOnDrop documentation for more details."]pub struct DiscardOnDrop<A: Discard>(_);
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 DiscardOnDrop::leak
function to unwrap it (which returns value
). This causes
it to no longer call discard
when it is dropped, which
means it will leak memory unless you manually call discard
.
See the module documentation for more details.
Methods
impl<A: Discard> DiscardOnDrop<A>
[src]
impl<A: Discard> DiscardOnDrop<A>
pub fn new(discarder: A) -> Self
[src]
pub fn new(discarder: A) -> Self
Creates a new DiscardOnDrop
.
When the DiscardOnDrop
is dropped it will automatically call discarder.discard()
.
See the module documentation for more details.
pub fn leak(this: Self) -> A
[src]
pub fn leak(this: Self) -> A
Returns the wrapped discarder
.
It will no longer automatically call discarder.discard()
, so this will leak memory
unless you manually call discarder.discard()
.
See the module documentation for more details.
This is implemented as a function (not a method) so that way it doesn't interfere with any of the
methods on discarder
.
Trait Implementations
impl<A: Debug + Discard> Debug for DiscardOnDrop<A>
[src]
impl<A: Debug + Discard> Debug for DiscardOnDrop<A>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<A: Discard> Drop for DiscardOnDrop<A>
[src]
impl<A: Discard> Drop for DiscardOnDrop<A>
impl<A: Discard> Deref for DiscardOnDrop<A>
[src]
impl<A: Discard> Deref for DiscardOnDrop<A>
type Target = A
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl<A: Discard> DerefMut for DiscardOnDrop<A>
[src]
impl<A: Discard> DerefMut for DiscardOnDrop<A>
Auto Trait Implementations
impl<A> Send for DiscardOnDrop<A> where
A: Send,
impl<A> Send for DiscardOnDrop<A> where
A: Send,
impl<A> Sync for DiscardOnDrop<A> where
A: Sync,
impl<A> Sync for DiscardOnDrop<A> where
A: Sync,