diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2025-08-26 18:18:24 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2025-08-26 18:18:24 -0400 |
| commit | a2fee1c18d9def1486a570fb3c98db5372c51238 (patch) | |
| tree | 3a6254672193b2f1b6c2375bc2f09b80ebc0fe0a /src/user/history.rs | |
| parent | 1e0493f079d011df56fe2ec93c44a0fea38f0531 (diff) | |
Store `User` instances using their events.
Diffstat (limited to 'src/user/history.rs')
| -rw-r--r-- | src/user/history.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/user/history.rs b/src/user/history.rs index f58e9c7..7c06a2d 100644 --- a/src/user/history.rs +++ b/src/user/history.rs @@ -2,7 +2,10 @@ use super::{ User, event::{Created, Event}, }; -use crate::event::{Instant, Sequence}; +use crate::{ + event::{Instant, Sequence}, + login::Login, +}; #[derive(Clone, Debug, Eq, PartialEq)] pub struct History { @@ -10,6 +13,21 @@ pub struct History { pub created: Instant, } +// Lifecycle interface +impl History { + pub fn begin(login: &Login, created: Instant) -> Self { + let Login { id, name } = login.clone(); + + Self { + user: User { + id: id.into(), + name, + }, + created, + } + } +} + // State interface impl History { pub fn as_of<S>(&self, sequence: S) -> Option<User> @@ -32,7 +50,7 @@ impl History { .into() } - pub fn events(&self) -> impl Iterator<Item = Event> + use<> { + pub fn events(&self) -> impl Iterator<Item = Event> + Clone + use<> { [self.created()].into_iter() } } |
