pub trait BumpAllocSafe { }
Expand description

A marker trait for types that are “safe” to bump alloc.

Objects that are bump-allocated will not have their Drop implementation called, which makes it easy to leak memory or other resources. If you put anything which heap allocates or manages open file descriptors or other resources into a Bump, and that thing relies on its Drop implementation to clean up after itself, then you need to find a new way to clean up after it yourself. This could be calling drop_in_place, or simply avoiding using such types in a Bump.

This is memory safe! Since destructors are never guaranteed to run in Rust, you can’t rely on them for enforcing memory safety. Therefore, implementing this trait is not unsafe in the Rust sense (which is only about memory safety). But instead of taking any T, bump allocation requires that you implement this marker trait for T just so that you know what you’re getting into.

Example

struct Point {
    x: u64,
    y: u64,
}

// We want to bump allocate `Point`s, so we implement
// `BumpAllocSafe` for them.
impl bumpalo::BumpAllocSafe for Point {}

Implementations on Foreign Types§

Implementors§