pub struct Cleaner { /* private fields */ }
Available on crate feature
cleaners
only.Expand description
A type capable of register
ing cleaning actions.
All the cleaning actions registered in a Cleaner
are run when it is dropped, unless they have been manually executed before.
Implementations§
Source§impl Cleaner
impl Cleaner
Sourcepub fn register(&self, action: impl FnOnce() + 'static) -> Cleanable
pub fn register(&self, action: impl FnOnce() + 'static) -> Cleanable
Registers a new cleaning action inside a Cleaner
.
This method returns a Cleanable
, which can be used to manually run the cleaning action.
§Avoiding memory leaks
Usually, Cleaner
s are stored inside a cycle-collected object. Make sure to never capture
a reference to the container object inside the action
closure, otherwise the object will
be leaked and the cleaning action will never be executed.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Cleaner
impl !RefUnwindSafe for Cleaner
impl !Send for Cleaner
impl !Sync for Cleaner
impl Unpin for Cleaner
impl !UnwindSafe for Cleaner
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