Expand description
The backdrop crate allows you to customize when and how your values are dropped.
The main entry point of this crate is the Backdrop<T, Strategy> wrapper type.
This will wrap any ‘normal’ type T with a zero-cost wrapper
that customizes how it is dropped based on the given Strategy,
which is a marker (zero-size compile-time only) type that implements the
BackdropStrategy<T> trait.
§Which strategy is best?
This probably depends very much on your application! Be sure to benchmark! For general applications, the following are good starting recommendations:
TrashThreadStrategyif you are working on a normal application where multithreading is possible.TokioTaskStrategyorTokioBlockingTaskStrategyif you are building anasyncapplication on top of the::tokiocrate.TrashQueueStrategyif you are writing a single-threaded application.
Backdrop also ships with a bunch of ‘simple testing’ strategies (LeakStrategy, TrivialStrategy, DebugStrategy, ThreadStrategy),
that can help to understand how backdrop works, as leaning tool to build your own strategies, and as benchmarking baseline.
§Limitations
Backdrop<T, S> implements the Deref and DerefMut traits, enabling you to use most methods available on T also on a Backdrop<T>.
On top of this, a bunch of common traits have been implemented for Backdrop<T, S> whenever they are implemented for T.
§Features
§Basic features
- You can disable the
stdfeature (enabled by default) to use this crate in no-std contexts. Withoutstd, none of thethread-based strategies are available. TheDebugStrategyis also disabled as it depends onprintln. - As long as the
allocfeature is not disabled (enabled by default; part of thestdfeature) the single-threadedTrashQueueStrategyis still available to you. If you also do not have access toalloc, you’ll probably want to create your own strategy for your particular no-std situation. - You can enable the optional
tokiofeature to get access to strategies that drop on a background tokio task. (C.f. thetokiomodule)
§Using Backdrop with traits from other crates
rkyvenablesArchive/Serialize/Deserializesupport forBackdrop<T, S>iff they are implemented forT.bytecheckenablesCheckBytessupport forBackdrop<T, S>iff implemented forT.
Need support for something else? Please open a PR and we can add it as an optional feature.
Modules§
- thread
std - tokio
tokio - The contents of this module are only available when the
tokiofeature is enabled.
Structs§
- Backdrop
- Wrapper to drop any value at a later time, such as in a background thread.
- Debug
Strategy std - ‘Wrapper’ strategy that prints out T when executed.
- Leak
Strategy - Strategy which will leak the contained value rather than dropping it.
- Thread
Strategy std - Strategy which drops the contained value in a newly spawned background thread.
- Tokio
Blocking Task Strategy tokio - Strategy which spawns a new ‘blocking’ tokio task which drops the contained value.
- Tokio
Task Strategy tokio - Strategy which spawns a new tokio task which drops the contained value.
- Trash
Queue Strategy alloc - Strategy which adds garbage to a global ‘trash
VecDeque’. - Trash
Thread Strategy std - Strategy which sends any to-be-dropped values to a dedicated ‘trash thread’
- Trivial
Strategy - Strategy which drops the contained value normally.
Traits§
- Backdrop
Strategy - The strategy to use to drop
T.
Type Aliases§
- Leak
Backdrop - Thread
Backdrop std - Convenient alias for a
Backdropthat uses theThreadStrategy - Tokio
Blocking Task Backdrop tokio - Convenient alias for a
Backdropthat uses theTokioBlockingTaskStrategy - Tokio
Task Backdrop tokio - Convenient alias for a
Backdropthat uses theTokioTaskStrategy - Trash
Thread Backdrop std - Convenient alias for a
Backdropthat uses theTrashThreadStrategy - Trivial
Backdrop