Trait 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§

Source

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§

Source§

impl<T> BackdropStrategy<T> for LeakStrategy

Source§

impl<T> BackdropStrategy<T> for TrivialStrategy

Source§

impl<T, InnerStrategy> BackdropStrategy<T> for DebugStrategy<InnerStrategy>
where T: Debug, InnerStrategy: BackdropStrategy<T>,

Available on crate feature std only.
Source§

impl<T: 'static> BackdropStrategy<T> for TrashQueueStrategy

Available on crate feature alloc only.
Source§

impl<T: Send + 'static> BackdropStrategy<T> for ThreadStrategy

Available on crate feature std only.
Source§

impl<T: Send + 'static> BackdropStrategy<T> for TokioBlockingTaskStrategy

Available on crate feature tokio only.
Source§

impl<T: Send + 'static> BackdropStrategy<T> for TokioTaskStrategy

Available on crate feature tokio only.
Source§

impl<T: Send + 'static> BackdropStrategy<T> for TrashThreadStrategy

Available on crate feature std only.
Source§

impl<T: Send + 'static> BackdropStrategy<T> for GlobalTrashThreadStrategy

Available on crate feature std only.