#![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::{Alloc, 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 mut counter = arena.alloc(0_u32);
*counter += 1;
*counter += 10;
println!("counter = {counter}");
let greeting = arena.alloc_str("hello, world");
println!("greeting = {greeting}");
let mut primes = arena.alloc_slice_copy([2, 3, 5, 7, 11, 13]);
primes[0] = 1; println!("primes = {:?}", &*primes);
let tokens = arena.alloc_slice_fill_with(3, |i| Token {
kind: "ident",
text: format!("name_{i}"),
});
println!("tokens = {:#?}", &*tokens);
let xs: Vec<Alloc<u64>> = (0..5).map(|i| arena.alloc(i as u64)).collect();
for r in &xs {
println!("x = {}", **r);
}
let rc = arena.alloc_arc(Point { x: 3.0, y: 4.0 });
let mut bump_ref = arena.alloc(vec![1, 2, 3]);
bump_ref.push(4);
println!("rc = {:?}, bump_ref = {:?}", &*rc, &*bump_ref);
drop((counter, greeting, primes, tokens, xs, bump_ref));
drop(arena);
println!("rc still valid after arena drop: {:?}", &*rc);
}