diff options
Diffstat (limited to 'src/federation/revision.rs')
| -rw-r--r-- | src/federation/revision.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/federation/revision.rs b/src/federation/revision.rs index 876ec15..3c6261b 100644 --- a/src/federation/revision.rs +++ b/src/federation/revision.rs @@ -12,24 +12,44 @@ use super::store::Id; /// A feature a revision adds. #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub(crate) enum Feature {} +pub(crate) enum Feature { + /// Merge events: a node its party lists, with its own key, builds on events it holds, + /// writing nothing (`Does::Merge`). + MergeEvents, +} impl Feature { /// Its name, in the IDs of the revisions that have it: never changed once released, /// and specific, so that a feature another build names alike is one it adds alike. pub(crate) fn name(self) -> &'static str { - match self {} + match self { + Feature::MergeEvents => "merge-events", + } } /// What it adds, in a line. pub(crate) fn what(self) -> &'static str { - match self {} + match self { + Feature::MergeEvents => { + "merge events, which a node its party lists signs with its own key, building \ + on events it holds and writing nothing" + } + } + } + + /// The revision that adds it. + pub(crate) fn revision(self) -> Revision { + let at = FEATURES + .iter() + .position(|feature| *feature == self) + .expect("every feature is in FEATURES"); + Revision(at + 1) } } /// The features, in the order revisions add them: revision n has the first n, the base /// revision none. Only ever appended to. -pub(crate) const FEATURES: &[Feature] = &[]; +pub(crate) const FEATURES: &[Feature] = &[Feature::MergeEvents]; /// A revision: how many of `FEATURES` it has. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)] @@ -113,6 +133,15 @@ mod tests { assert_eq!(Revision::of(&Id::of(b"[]")), Some(Revision(0))); assert_eq!(Revision::of(&Id::of(b"[\"elsewhere\"]")), None); assert_eq!(Revision::default().to_string(), "the base revision"); + assert_eq!( + Feature::MergeEvents.revision().to_string(), + "revision 1 (merge-events)" + ); + assert_eq!( + Revision(1).id(), + Id::of(br#"["merge-events"]"#), + "a released revision's ID changes never" + ); let names: Vec<&str> = FEATURES.iter().map(|feature| feature.name()).collect(); let distinct: std::collections::BTreeSet<&str> = names.iter().copied().collect(); assert_eq!(distinct.len(), names.len(), "a feature named twice"); |
