#![allow(clippy::unwrap_used, reason = "example code")]
#![allow(clippy::missing_panics_doc, reason = "example code")]
#![allow(clippy::std_instead_of_core, reason = "example uses std")]
#![allow(dead_code, reason = "Debug printout consumes the fields")]
#![allow(clippy::cast_possible_truncation, reason = "example data is small")]
#![allow(clippy::cast_sign_loss, reason = "example data is small")]
use multitude::Arena;
#[derive(Debug)]
struct Token {
kind: &'static str,
text: String,
}
#[derive(Debug)]
struct Point {
x: f64,
y: f64,
}
fn main() {
let arena = Arena::new();
let counter: &mut u32 = arena.alloc(0);
*counter += 1;
*counter += 10;
println!("counter = {counter}");
let greeting: &mut str = arena.alloc_str("hello, world");
println!("greeting = {greeting}");
let primes: &mut [u32] = arena.alloc_slice_copy([2, 3, 5, 7, 11, 13]);
primes[0] = 1; println!("primes = {primes:?}");
let tokens: &mut [Token] = arena.alloc_slice_fill_with(3, |i| Token {
kind: "ident",
text: format!("name_{i}"),
});
println!("tokens = {tokens:#?}");
let xs: Vec<&mut u64> = (0..5).map(|i| arena.alloc(i as u64)).collect();
for r in &xs {
println!("x = {}", **r);
}
let rc = arena.alloc_rc(Point { x: 3.0, y: 4.0 });
let bump_ref: &mut Vec<i32> = arena.alloc(vec![1, 2, 3]);
bump_ref.push(4);
println!("rc = {:?}, bump_ref = {bump_ref:?}", &*rc);
drop(arena);
println!("rc still valid after arena drop: {:?}", &*rc);
}