[−][src]Macro moore::node_storage
Create a new table that implements the NodeStorage
trait.
The resulting table can then be used to store nodes in a type safe manner.
Example
#[macro_use] extern crate moore_common; use moore_common::score::NodeStorage; #[derive(PartialEq, Eq, Hash, Debug)] struct FooRef(usize); #[derive(PartialEq, Eq, Hash, Debug)] struct BarRef(usize); #[derive(PartialEq, Eq, Debug)] struct Foo; #[derive(PartialEq, Eq, Debug)] struct Bar; node_storage!(NodeTable<'tn>: foos: FooRef => &'tn Foo, bars: BarRef => &'tn Bar, ); let foo = &Foo; let bar = &Bar; let mut tbl = NodeTable::new(); tbl.set(FooRef(0), foo); tbl.set(BarRef(1), bar); assert_eq!(tbl.get(&FooRef(0)), Some(&foo)); assert_eq!(tbl.get(&BarRef(1)), Some(&bar)); // The following would produce a compiler error due to the type mismatch: // assert_eq!(tbl.get(&BarRef(0)), Some(&foo)); // assert_eq!(tbl.get(&FooRef(1)), Some(&bar));