pub struct StringId<Id, Lookup>where
Lookup: StrLookup,{ /* private fields */ }
Expand description
Manage identifier both as human readable string and unique number.
StringId
is designed to be used with new-type pattern
and use generics to adapt to different usages.
§Generics
Id
- the type of the id associated with thestr
Lookup
- the type who allow to lookup forstr
corresponding to id
The Lookup
should implement StrLookup
.
The constraints of Id
type, depends of the type used as Lookup
.
With provided implementation of StrLookup
Id
is generated from std
with cityhasher::hash
,
so Id
should implement cityhasher::FromCityHash
and could only be be u32
or u64
.
The size of a StringId
variable is the size of the Id
type.
StrLookupEmpty
is an implementation of StrLookup
who don’t keep the str
.
§Example
#[strlookup_hashmap(key = u32, store = StringStrStore, size = 128)]
struct CustomIdLookup;
#[derive(Debug, Clone, Copy, StringIdImpl)]
struct CustomId(StringId<u32, CustomIdLookup>);
// Create an id from the str 'resource_1'
let res_id = CustomId::from_str("resource_1").unwrap();
// CustomId can be copied
let res_id_copy = res_id;
assert_eq!(res_id_copy, res_id);
// Two CustomId created from the same `str` are equal.
let res_id_bis = CustomId::from_str("resource_1").unwrap();
assert_eq!(res_id, res_id_bis);
// The StringId variable keep the size of Id. Check :
assert_eq!(
size_of::<u32>(),
size_of::<CustomId>()
);
Implementations§
Trait Implementations§
Source§impl<Id, Lookup> Clone for StringId<Id, Lookup>
Manual implementation to avoid than Lookup
should implement Clone
impl<Id, Lookup> Clone for StringId<Id, Lookup>
Manual implementation to avoid than Lookup
should implement Clone
This happen with implementation generated by derive macro Clone
.
Source§impl<Id, Lookup> Ord for StringId<Id, Lookup>
impl<Id, Lookup> Ord for StringId<Id, Lookup>
Source§impl<Id, Lookup> PartialOrd for StringId<Id, Lookup>
impl<Id, Lookup> PartialOrd for StringId<Id, Lookup>
impl<Id, Lookup> Copy for StringId<Id, Lookup>
Manual implementation to avoid than Lookup
should implement Copy
This happen with implementation generated by derive macro Copy
.