zone-alloc-strong-handle-derive

![Latest Version]

This crate provides a procedural macro for deriving the StrongHandle interface on simple wrappers around the Handle type when working with the StrongRegistry container in the zone-alloc crate.

toml [dependencies] zone-alloc = "0.1" zone-alloc-strong-handle-derive = "0.1"

Usage

This crate defines one procedural macro:

Example

Linked List Nodes with [Arena<T>]

``` use zonealloc::{ Handle, StrongRegistry, }; use zoneallocstronghandle_derive::StrongHandle;

[derive(Clone, Copy, Debug, PartialEq, Eq, StrongHandle)]

struct NodeHandle(Handle);

[derive(Debug, PartialEq, Eq)]

struct Node { parent: Option, value: T, }

impl Node { pub fn new(parent: Option, value: T) -> Self { Self { parent, value } } }

fn main() { let registry = StrongRegistry::>::new(); let roothandle = registry.register(Node::new(None, "first")); let handle = registry.register(Node::new(Some(roothandle), "second")); let handle = registry.register(Node::new(Some(handle), "third")); registry.getmut(roothandle).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");

} ```