willow_data_model/entry/keylike.rs
1use crate::prelude::*;
2
3/// A keylike value is one that can be used to "address" an [Entry](https://willowprotocol.org/specs/data-model/index.html#Entry) within a [namespace](https://willowprotocol.org/specs/data-model/index.html#namespace).
4///
5/// Within a namespace, entries can be uniquely identified by their [subspace_id](https://willowprotocol.org/specs/data-model/index.html#entry_subspace_id) (of type `S`) and their [path](https://willowprotocol.org/specs/data-model/index.html#entry_path).
6pub trait Keylike<const MCL: usize, const MCC: usize, const MPL: usize, S> {
7 /// Returns the [subspace_id](https://willowprotocol.org/specs/data-model/index.html#entry_subspace_id) of `self`.
8 fn wdm_subspace_id(&self) -> &S;
9
10 /// Returns the [path](https://willowprotocol.org/specs/data-model/index.html#entry_path) of `self`.
11 fn wdm_path(&self) -> &Path<MCL, MCC, MPL>;
12}
13
14impl<const MCL: usize, const MCC: usize, const MPL: usize, S> Keylike<MCL, MCC, MPL, S>
15 for (S, Path<MCL, MCC, MPL>)
16{
17 fn wdm_subspace_id(&self) -> &S {
18 &self.0
19 }
20
21 fn wdm_path(&self) -> &Path<MCL, MCC, MPL> {
22 &self.1
23 }
24}