[−][src]Trait urid::URIDCollection
A store of pre-mapped URIDs
This trait can be used to easily cache URIDs. The usual way of creating such a collection is to define a struct of URID<T>
s, where T
implements UriBound
, and then using the derive macro to implement URIDCollection
for it. Then, you can populate it with a map and access it any time, even in a real-time-sensitive context.
Usage example:
// Defining all URI bounds. #[uri("urn:my-type-a")] struct MyTypeA; #[uri("urn:my-type-b")] struct MyTypeB; // Defining the collection. #[derive(URIDCollection)] struct MyCollection { my_type_a: URID<MyTypeA>, my_type_b: URID<MyTypeB>, } // Creating a mapper and collecting URIDs. let map = HashURIDMapper::new(); let collection = MyCollection::from_map(&map).unwrap(); // Asserting. assert_eq!(1, collection.my_type_a); assert_eq!(2, collection.my_type_b);