summaryrefslogtreecommitdiff
path: root/src/channel/history.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/channel/history.rs')
-rw-r--r--src/channel/history.rs69
1 files changed, 0 insertions, 69 deletions
diff --git a/src/channel/history.rs b/src/channel/history.rs
deleted file mode 100644
index 85da5a5..0000000
--- a/src/channel/history.rs
+++ /dev/null
@@ -1,69 +0,0 @@
-use itertools::Itertools as _;
-
-use super::{
- Channel, Id,
- event::{Created, Deleted, Event},
-};
-use crate::event::{Instant, Sequence};
-
-#[derive(Clone, Debug, Eq, PartialEq)]
-pub struct History {
- pub channel: Channel,
- pub deleted: Option<Instant>,
-}
-
-// State interface
-impl History {
- pub fn id(&self) -> &Id {
- &self.channel.id
- }
-
- // Snapshot of this channel as it was when created. (Note to the future: it's
- // okay if this returns a redacted or modified version of the channel. If we
- // implement renames by redacting the original name, then this should return the
- // renamed channel, not the original, even if that's not how it was "as
- // created.")
- pub fn as_created(&self) -> Channel {
- self.channel.clone()
- }
-
- pub fn as_of<S>(&self, sequence: S) -> Option<Channel>
- where
- S: Into<Sequence>,
- {
- self.events()
- .filter(Sequence::up_to(sequence.into()))
- .collect()
- }
-
- // Snapshot of this channel as of all events recorded in this history.
- pub fn as_snapshot(&self) -> Option<Channel> {
- self.events().collect()
- }
-}
-
-// Event factories
-impl History {
- pub fn events(&self) -> impl Iterator<Item = Event> + use<> {
- [self.created()]
- .into_iter()
- .merge_by(self.deleted(), Sequence::merge)
- }
-
- fn created(&self) -> Event {
- Created {
- channel: self.channel.clone(),
- }
- .into()
- }
-
- fn deleted(&self) -> Option<Event> {
- self.deleted.map(|instant| {
- Deleted {
- instant,
- id: self.channel.id.clone(),
- }
- .into()
- })
- }
-}