extern crate froggy; use froggy::{Storage, WeakPointer}; struct Node { value: String, next: Option>, } impl Drop for Node { fn drop(&mut self) { println!("{} destroyed", &self.value); } } fn main() { let mut storage = Storage::new(); let node1 = storage.create(Node { value: "Node 1".to_string(), next: None, }); let node2 = storage.create(Node { value: "Node 2".to_string(), next: None, }); storage[&node1].next = Some(node2.downgrade()); storage[&node2].next = Some(node1.downgrade()); for node in &storage { let value = node.next.as_ref().map_or("None".into(), |next| { let ptr = next.upgrade().unwrap(); storage[&ptr].value.clone() }); println!("{} has `next` field with value {}", node.value, value); } }