1use comet::GCPlatform;
2use comet_api::{*,cell::Heap};
3
4
5struct Node<T: TraceTrait + 'static + std::fmt::Debug> {
6 next: Option<GcPointer<Node<T>>>,
7 value: T
8}
9
10impl<T: Trace + 'static + std::fmt::Debug> GcCell for Node<T> {}
11
12impl<T: Trace + std::fmt::Debug> Trace for Node<T> {
13 fn trace(&self, vis: &mut Visitor) {
14 println!("Trace {:p} {:?}",self,self);
15 self.value.trace(vis);
16 self.next.trace(vis);
17 }
18}
19impl<T: Trace + std::fmt::Debug> Finalize<Self> for Node<T> {}
20
21impl<T: std::fmt::Debug + Trace> std::fmt::Debug for Node<T> {
22 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
23 write!(f,"Node {{next: {:?}, value: {:?} }}",self.next,self.value)
24 }
25}
26
27impl<T: std::fmt::Debug + Trace> Drop for Node<T> {
28 fn drop(&mut self) {
29 println!("drop {:p} {:?}",self,self);
30 }
31}
32
33fn main() {
34 GCPlatform::initialize();
35
36 let mut heap = Heap::new(None);
37
38 let mut head = heap.allocate(Node {next: None,value: 0i32 });
39 head.next = Some(heap.allocate(Node {next: None, value: 1}));
40 heap.gc();
41
42 println!("{:p}",&head);
43 head.next = None;
44 heap.gc();
45 println!("{:p}", &head);
46}