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);
});
}
}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
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>,
std only.impl<T: 'static> BackdropStrategy<T> for TrashQueueStrategy
alloc only.impl<T: Send + 'static> BackdropStrategy<T> for ThreadStrategy
std only.impl<T: Send + 'static> BackdropStrategy<T> for TokioBlockingTaskStrategy
tokio only.impl<T: Send + 'static> BackdropStrategy<T> for TokioTaskStrategy
tokio only.impl<T: Send + 'static> BackdropStrategy<T> for TrashThreadStrategy
std only.impl<T: Send + 'static> BackdropStrategy<T> for GlobalTrashThreadStrategy
std only.