Trait backdrop::BackdropStrategy
source · pub trait BackdropStrategy<T> {
// Required method
fn execute(droppable: T);
}
Expand description
The strategy to use to drop T
.
Most implementations of this trait place additional requirements on T
.
For instance, all strategies that move T to a separate thread to be dropped there
introduce a T: Send + 'static
bound.
Required Methods§
sourcefn execute(droppable: T)
fn execute(droppable: T)
Called whenever T
should be dropped.
The trivial implementation (and indeed, TrivialStrategy
is implemented this way)
is to do nothing. Then T
will just directly be dropped right here, right now, because it is passed by value:
ⓘ
pub struct TrivialStrategy();
impl<T> BackdropStrategy<T> for TrivialStrategy {
fn execute(_droppable: T) {
}
}
Or, for clarity:
ⓘ
pub struct TrivialStrategy();
impl<T> BackdropStrategy<T> for TrivialStrategy {
fn execute(droppable: T) {
core::mem::drop(droppable)
}
}
But obviously that is not very exciting/helpful.
Most implementations move the T
to somewhere else somehow, and then it will be dropped there.
To give you another example, here is how ThreadStrategy
works:
ⓘ
pub struct ThreadStrategy();
impl<T: Send + 'static> BackdropStrategy<T> for ThreadStrategy {
fn execute(droppable: T) {
std::thread::spawn(|| {
core::mem::drop(droppable);
});
}
}
Implementors§
impl<T> BackdropStrategy<T> for LeakStrategy
impl<T> BackdropStrategy<T> for TrivialStrategy
impl<T, InnerStrategy> BackdropStrategy<T> for DebugStrategy<InnerStrategy>where T: Debug, InnerStrategy: BackdropStrategy<T>,
Available on crate feature
std
only.impl<T: 'static> BackdropStrategy<T> for TrashQueueStrategy
Available on crate feature
alloc
only.impl<T: Send + 'static> BackdropStrategy<T> for ThreadStrategy
Available on crate feature
std
only.impl<T: Send + 'static> BackdropStrategy<T> for TokioBlockingTaskStrategy
Available on crate feature
tokio
only.impl<T: Send + 'static> BackdropStrategy<T> for TokioTaskStrategy
Available on crate feature
tokio
only.impl<T: Send + 'static> BackdropStrategy<T> for TrashThreadStrategy
Available on crate feature
std
only.impl<T: Send + 'static> BackdropStrategy<T> for GlobalTrashThreadStrategy
Available on crate feature
std
only.