Skip to main content

dope_core/driver/route/table/
key.rs

1use core::hash;
2
3use o3::depot::arena::slab::external;
4
5use crate::driver::{
6    route,
7    route::{indices, table},
8};
9
10#[derive(Clone, Copy)]
11#[repr(transparent)]
12pub struct Key<Tag: route::Tag>(table::Parts<Tag>);
13
14impl<Tag: route::Tag> PartialEq for Key<Tag> {
15    fn eq(&self, other: &Self) -> bool {
16        self.0 == other.0
17    }
18}
19
20impl<Tag: route::Tag> Eq for Key<Tag> {}
21
22impl<Tag: route::Tag> hash::Hash for Key<Tag> {
23    fn hash<H: hash::Hasher>(&self, state: &mut H) {
24        self.0.hash(state);
25    }
26}
27
28impl<Tag: route::Tag> Key<Tag> {
29    /// Retains the bound and generation of an identity emitted by route storage.
30    pub(in crate::driver::route::table) const fn new(
31        key: external::Key<route::Epoch, Tag>,
32    ) -> Self {
33        Self(table::Parts::new(
34            indices::SlotIndex::from_field(key.index() as u64),
35            key.generation(),
36        ))
37    }
38
39    pub const fn slot(self) -> indices::SlotIndex {
40        self.0.slot()
41    }
42
43    pub const fn epoch(self) -> route::Epoch {
44        self.0.epoch()
45    }
46
47    pub const fn parts(self) -> table::Parts<Tag> {
48        self.0
49    }
50}
51
52const _: () = {
53    assert!(core::mem::size_of::<Key<route::KeyTag<1>>>() == 2 * core::mem::size_of::<u64>());
54};