willow_data_model/parameters.rs
1use crate::entry::Entry;
2
3/// A type for identifying [namespaces](https://willowprotocol.org/specs/data-model/index.html#namespace).
4/// [Definition](https://willowprotocol.org/specs/data-model/index.html#NamespaceId).
5
6pub trait NamespaceId: Eq + Default + Clone {}
7
8/// A type for identifying [subspaces](https://willowprotocol.org/specs/data-model/index.html#subspace).
9/// [Definition](https://willowprotocol.org/specs/data-model/index.html#SubspaceId).
10///
11/// ## Implementation notes
12///
13/// The [`Default`] implementation **must** return the least element in the total order of [`SubspaceId`].
14pub trait SubspaceId: Ord + Default + Clone {
15 /// Return the next possible value in the set of all [`SubspaceId`].
16 /// e.g. the successor of 3 is 4.
17 fn successor(&self) -> Option<Self>;
18}
19
20/// A totally ordered type for [content-addressing](https://en.wikipedia.org/wiki/Content_addressing) the data that Willow stores.
21/// [Definition](https://willowprotocol.org/specs/data-model/index.html#PayloadDigest).
22pub trait PayloadDigest: Ord + Default + Clone {}
23
24/// Determines whether this type (nominally a [`AuthorisationToken`](https://willowprotocol.org/specs/data-model/index.html#AuthorisationToken)) is able to prove write permission for a given [`Entry`].
25///
26/// ## Type parameters
27///
28/// - `N` - The type used for the [`Entry`]'s [`NamespaceId`].
29/// - `S` - The type used for the [`Entry`]'s [`SubspaceId`].
30/// - `PD` - The type used for the [`Entry`]'s [`PayloadDigest`].
31pub trait AuthorisationToken<
32 const MCL: usize,
33 const MCC: usize,
34 const MPL: usize,
35 N: NamespaceId,
36 S: SubspaceId,
37 PD: PayloadDigest,
38>
39{
40 /// Determine whether this type (nominally a [`AuthorisationToken`](https://willowprotocol.org/specs/data-model/index.html#AuthorisationToken)) is able to prove write permission for a given [`Entry`].
41 fn is_authorised_write(&self, entry: &Entry<MCL, MCC, MPL, N, S, PD>) -> bool;
42}