Skip to main content

URIDCollection

Trait URIDCollection 

Source
pub trait URIDCollection: Sized {
    // Required method
    fn from_map<M: Map + ?Sized>(map: &M) -> Option<Self>;
}
Expand description

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

Required Methods§

Source

fn from_map<M: Map + ?Sized>(map: &M) -> Option<Self>

Construct the collection from the mapper.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§