nearest 0.4.5

Self-relative pointer library for region-based allocation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//! A `Ref` must not escape the session closure.

use nearest::{Flat, NearList, Ref, Region, empty};

#[derive(Flat, Debug)]
struct Block {
  name: u32,
  items: NearList<u32>,
}

fn main() {
  let mut region: Region<Block> = Region::new(Block::make(42, empty()));
  let escaped: Ref<'_, Block> = region.session(|s| {
    s.root() // Ref escapes the closure — must not compile.
  });
  let _ = escaped;
}