Skip to main content

Crate alloc_once

Crate alloc_once 

Source
Expand description

alloc_once! — allocate several different-typed values in a single bump allocation and get back a guard that owns the arena.

This crate is a thin facade over bumpalo: it re-exports the [alloc_once] procedural macro and provides the AllocOnce guard the macro expands into. Callers never name bumpalo themselves.

use alloc_once::alloc_once;

let mut guard = alloc_once!(1i32, [10u8, 20, 30], "hello");
let (n, bytes, s) = &mut *guard;   // independent &mut to each field
*n += 41;
bytes[0] = 99;
assert_eq!(*n, 42);
assert_eq!(bytes[0], 99);
assert_eq!(*s, "hello");
// `guard` drops here: it runs the values' destructors, then frees the arena.

Macros§

alloc_once
Allocate several (possibly different-typed) values in a single bump allocation and return a guard that owns the backing arena.

Structs§

AllocOnce
Owns a bump arena and the single value allocated inside it.