Expand description
Procedural macro for deriving the [zone_alloc::StrongHandle
] interface on simple wrappers
around [zone_alloc::Handle
].
Example
use zone_alloc::{
Handle,
StrongRegistry,
};
use zone_alloc_strong_handle_derive::StrongHandle;
#[derive(Clone, Copy, Debug, PartialEq, Eq, StrongHandle)]
struct NodeHandle(Handle);
#[derive(Debug, PartialEq, Eq)]
struct Node<T> {
parent: Option<NodeHandle>,
value: T,
}
impl<T> Node<T> {
pub fn new(parent: Option<NodeHandle>, value: T) -> Self {
Self { parent, value }
}
}
fn main() {
let registry = StrongRegistry::<NodeHandle, Node<&str>>::new();
let root_handle = registry.register(Node::new(None, "first"));
let handle = registry.register(Node::new(Some(root_handle), "second"));
let handle = registry.register(Node::new(Some(handle), "third"));
registry.get_mut(root_handle).unwrap().parent = Some(handle);
let node = registry.get(handle).unwrap();
assert_eq!(node.value, "third");
let node = registry.get(node.parent.unwrap()).unwrap();
assert_eq!(node.value, "second");
let node = registry.get(node.parent.unwrap()).unwrap();
assert_eq!(node.value, "first");
let node = registry.get(node.parent.unwrap()).unwrap();
assert_eq!(node.value, "third");
}