diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-10-04 14:10:55 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-10-04 14:10:55 -0400 |
| commit | 9bd6d9862b1c243def02200bca2cfbf578ad2a2f (patch) | |
| tree | 44d20c937eee728e9b33ff093b3945a3ab2593dd /src/channel/history.rs | |
| parent | 7f12fd41c2941a55a6437f24e4f780104a718790 (diff) | |
Clean up naming and semantics of history accessors.
Diffstat (limited to 'src/channel/history.rs')
| -rw-r--r-- | src/channel/history.rs | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/src/channel/history.rs b/src/channel/history.rs index 3cc7d9d..bd45d8d 100644 --- a/src/channel/history.rs +++ b/src/channel/history.rs @@ -1,6 +1,6 @@ use super::{ event::{Created, Deleted, Event}, - Channel, + Channel, Id, }; use crate::event::Instant; @@ -11,7 +11,28 @@ pub struct History { 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() + } +} + +// Event factories +impl History { + pub fn events(&self) -> impl Iterator<Item = Event> { + [self.created()].into_iter().chain(self.deleted()) + } + fn created(&self) -> Event { Event { instant: self.created, @@ -31,12 +52,4 @@ impl History { .into(), }) } - - pub fn events(&self) -> impl Iterator<Item = Event> { - [self.created()].into_iter().chain(self.deleted()) - } - - pub fn snapshot(&self) -> Channel { - self.channel.clone() - } } |
