use super::{ event::{Created, Deleted, Event}, Channel, }; use crate::event::Instant; #[derive(Clone, Debug, Eq, PartialEq)] pub struct History { pub channel: Channel, pub created: Instant, pub deleted: Option, } impl History { fn created(&self) -> Event { Event { instant: self.created, kind: Created { channel: self.channel.clone(), } .into(), } } fn deleted(&self) -> Option { self.deleted.map(|instant| Event { instant, kind: Deleted { channel: self.channel.id.clone(), } .into(), }) } pub fn events(&self) -> impl Iterator { [self.created()].into_iter().chain(self.deleted()) } pub fn snapshot(&self) -> Channel { self.channel.clone() } }