-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfeatures.rs
58 lines (46 loc) · 1.06 KB
/
features.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#![feature(arbitrary_self_types)]
use elise::{Gc, GcStore};
#[derive(elise::GC)]
#[gc(finalize)]
struct Foo<'root> {
#[gc]
item: GcStore<'root, i32>,
#[gc]
vec: Vec<GcStore<'root, i32>>,
#[gc]
option: Option<GcStore<'root, i32>>,
local: i32,
}
impl<'root> Foo<'root> {
fn new() -> Foo<'root> {
Foo {
item: GcStore::new(0),
vec: vec![GcStore::new(1), GcStore::new(2), GcStore::new(3)],
option: Some(GcStore::new(4)),
local: 5,
}
}
fn print_nonlocal(self: Gc<'_, Self>) {
println!("{}", self.item());
for elem in self.vec() {
println!("{}", elem);
}
if let Some(thing) = self.option() {
println!("{}", thing);
}
}
}
impl<'root> elise::Finalize for Foo<'root> {
fn finalize(&mut self) {
println!("{}", self.local);
}
}
fn main() {
{
elise::letroot!(root);
let foo = root.gc(Foo::new());
elise::collect();
foo.print_nonlocal();
}
elise::collect();
}