pub trait Discard {
// Required method
fn discard(self);
}
Expand description
This trait is very similar to Drop
:
it allows for cleaning up memory and resources when they are no longer needed.
However, unlike Drop
you need to
manually call the discard
method.
It is extremely common to use DiscardOnDrop
, which will cause it
to automatically call the discard
method when it is dropped. In that situation
Discard
behaves exactly the same as Drop
.
You can use DiscardOnDrop::leak
to intentionally leak the value
(which causes discard
to not be called), and then later you can manually call
discard
to clean up the resources, even after the resources have been leaked.
See the module documentation for more details.
Required Methods§
Sourcefn discard(self)
fn discard(self)
This consumes the value and cleans up any memory / resources / etc. that the value was using.
See the module documentation for more details.