Skip to main content

Module registry

Module registry 

Source
Expand description

Strongly typed identifiers and registries.

This module provides:

  • Identifier: a trait for strongly typed IDs backed by usize
  • Identified<Id, T>: a value paired with its typed ID
  • Registry<Id, T>: a typed vector indexed by Id

§Example

use jstd::Identifier;
use jstd::registry::Registry;

#[derive(Identifier)]
struct NodeId(usize);

let mut registry = Registry::<NodeId, &str>::default();
let a = registry.push("a");
let b = registry.push("b");

assert_eq!(usize::from(a), 0);
assert_eq!(usize::from(b), 1);
assert_eq!(registry[a], "a");
assert_eq!(registry[b], "b");

Structs§

Identified
A value paired with its typed identifier.
IntoIter
Iter
IterMut
Registry
A strongly typed vector

Traits§

Identifier
Typed identifier trait used by Registry.