ghost_gc/
lib.rs

1#![feature(ptr_metadata, allocator_api)]
2#![deny(unsafe_op_in_unsafe_fn)]
3#![doc = include_str!("../README.md")]
4
5extern crate alloc;
6
7mod arena;
8mod collect;
9mod context;
10mod gc;
11mod gc_vtable;
12mod unique_gc;
13mod write;
14
15mod gc_box;
16mod gc_weak;
17mod invariant;
18pub mod locked;
19
20pub use arena::{Arena, Rootable};
21pub use collect::Collect;
22pub use context::{Collector, Mutation};
23pub use gc::Gc;
24pub use gc_weak::Weak;
25pub use unique_gc::UniqueGc;
26pub use write::Write;
27
28use invariant::Invariant;
29
30pub fn once_arena<F, R>(f: F) -> R
31where
32    F: for<'b> FnOnce(&Mutation<'b>) -> R,
33{
34    struct OnceRoot;
35
36    impl Rootable for OnceRoot {
37        type Root<'a> = OnceRoot;
38    }
39
40    unsafe impl Collect for OnceRoot {
41        const NEEDS_TRACE: bool = false;
42
43        fn trace(&self, _c: &Collector) {}
44    }
45
46    let arena = Arena::<OnceRoot>::new(|_| OnceRoot);
47
48    arena.view(|_, mt| f(mt))
49}