type_registry/raw/
registry_id.rs

1use std::hash::{Hash, Hasher};
2use crate::logical::Registry;
3use crate::raw::RegistryInfo;
4
5/// Identifier of a particular [type-registry](Registry).
6#[derive(Copy, Clone, Debug, Eq)]
7pub struct RegistryId {
8    /// Function which gets the [information](RegistryInfo) about the identified
9    /// [registry](Registry). This function is unique for each type of registry, so its address is
10    /// used as the identifier internally.
11    get_registry_info: fn() -> RegistryInfo
12}
13
14impl RegistryId {
15    /// Gets the ID for a particular [registry](Registry).
16    pub const fn of<R: Registry + ?Sized>() -> Self {
17        Self {
18            get_registry_info: RegistryInfo::of::<R>
19        }
20    }
21    
22    /// Gets the [information](RegistryInfo) about the identified [registry](Registry).
23    pub fn info(&self) -> RegistryInfo {
24        (self.get_registry_info)()
25    }
26}
27
28impl PartialEq for RegistryId {
29    fn eq(&self, other: &Self) -> bool {
30        self.info().type_id() == other.info().type_id()
31    }
32}
33
34impl Hash for RegistryId {
35    fn hash<H: Hasher>(&self, state: &mut H) {
36        self.info().type_id().hash(state)
37    }
38}