logoalt Hacker News

kibwentoday at 6:15 PM0 repliesview on HN

Arenas in Rust work very well with lifetimes. In fact arenas benefit greatly from lifetimes, because lifetimes allow them to uphold the usual Rust safety guarantees about preventing use-after-free. For example, here's the bumpalo crate in action:

    let mut arena = Bump::new(); // create arena
    
    let foo = arena.alloc(Foo { x: 42 }); // allocate item in arena
    
    bump.reset(); // clear arena
    
    foo.x += 1; // compiler error preventing use-after-free