pub trait IdHashItem {
type Key<'a>: Eq + Hash
where Self: 'a;
// Required methods
fn key(&self) -> Self::Key<'_>;
fn upcast_key<'short, 'long: 'short>(
long: Self::Key<'long>,
) -> Self::Key<'short>;
}Expand description
An element stored in an IdHashMap.
This trait is used to define the key type for the map.
§Examples
use iddqd::{IdHashItem, IdHashMap, id_upcast};
// Define a struct with a key.
#[derive(Debug, PartialEq, Eq, Hash)]
struct MyItem {
id: String,
value: u32,
}
// Implement IdHashItem for the struct.
impl IdHashItem for MyItem {
// Keys can borrow from the item.
type Key<'a> = &'a str;
fn key(&self) -> Self::Key<'_> {
&self.id
}
id_upcast!();
}
// Create an IdHashMap and insert items.
let mut map = IdHashMap::new();
map.insert_unique(MyItem { id: "foo".to_string(), value: 42 }).unwrap();
map.insert_unique(MyItem { id: "bar".to_string(), value: 20 }).unwrap();Required Associated Types§
Required Methods§
Sourcefn upcast_key<'short, 'long: 'short>(
long: Self::Key<'long>,
) -> Self::Key<'short>
fn upcast_key<'short, 'long: 'short>( long: Self::Key<'long>, ) -> Self::Key<'short>
Upcasts the key to a shorter lifetime, in effect asserting that the
lifetime 'a on IdHashItem::Key is covariant.
Typically implemented via the id_upcast macro.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<'b, T: 'b + ?Sized + IdHashItem> IdHashItem for &'b T
impl<'b, T: 'b + ?Sized + IdHashItem> IdHashItem for &'b T
Source§impl<'b, T: 'b + ?Sized + IdHashItem> IdHashItem for &'b mut T
impl<'b, T: 'b + ?Sized + IdHashItem> IdHashItem for &'b mut T
Source§impl<T: ?Sized + IdHashItem> IdHashItem for Arc<T>
impl<T: ?Sized + IdHashItem> IdHashItem for Arc<T>
Source§impl<T: ?Sized + IdHashItem> IdHashItem for Box<T>
impl<T: ?Sized + IdHashItem> IdHashItem for Box<T>
Source§impl<T: ?Sized + IdHashItem> IdHashItem for Rc<T>
impl<T: ?Sized + IdHashItem> IdHashItem for Rc<T>
Implementors§
Source§impl<T: BiHashItem> IdHashItem for iddqd::bi_hash_map::ByK1<T>
Available on crate feature daft only.
impl<T: BiHashItem> IdHashItem for iddqd::bi_hash_map::ByK1<T>
Available on crate feature
daft only.type Key<'a> = <T as BiHashItem>::K1<'a> where T: 'a
Source§impl<T: BiHashItem> IdHashItem for iddqd::bi_hash_map::ByK2<T>
Available on crate feature daft only.
impl<T: BiHashItem> IdHashItem for iddqd::bi_hash_map::ByK2<T>
Available on crate feature
daft only.type Key<'a> = <T as BiHashItem>::K2<'a> where T: 'a
Source§impl<T: IdHashItem> IdHashItem for IdLeaf<T>
Available on crate feature daft only.
impl<T: IdHashItem> IdHashItem for IdLeaf<T>
Available on crate feature
daft only.type Key<'a> = <T as IdHashItem>::Key<'a> where T: 'a
Source§impl<T: TriHashItem> IdHashItem for iddqd::tri_hash_map::ByK1<T>
Available on crate feature daft only.
impl<T: TriHashItem> IdHashItem for iddqd::tri_hash_map::ByK1<T>
Available on crate feature
daft only.type Key<'a> = <T as TriHashItem>::K1<'a> where T: 'a
Source§impl<T: TriHashItem> IdHashItem for iddqd::tri_hash_map::ByK2<T>
Available on crate feature daft only.
impl<T: TriHashItem> IdHashItem for iddqd::tri_hash_map::ByK2<T>
Available on crate feature
daft only.type Key<'a> = <T as TriHashItem>::K2<'a> where T: 'a
Source§impl<T: TriHashItem> IdHashItem for ByK3<T>
Available on crate feature daft only.
impl<T: TriHashItem> IdHashItem for ByK3<T>
Available on crate feature
daft only.