[][src]Macro moore::node_storage

macro_rules! node_storage {
    ($name:ident<$($lt:tt),+>: $($node_name:ident : $node_ref:ty => $node:ty,)+) => { ... };
    ($name:ident<$($lt:tt),+> where ($($wh:tt)+): $($node_name:ident : $node_ref:ty => $node:ty,)+) => { ... };
    (STRUCT_IMPL $name:ident; $($lt:tt),+; $($node_name:ident, $node_ref:ty, $node:ty;)*) => { ... };
    (TRAIT_IMPL $name:ident; $($lt:tt),+; $node_name:ident, $node_ref:ty, $node:ty; $($tail_name:ident, $tail_ref:ty, $tail:ty;)*) => { ... };
    (TRAIT_IMPL $name:ident; $($lt:tt),*;) => { ... };
}

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));