use surreal_sync_core::{Change, RelationChange};
#[derive(Debug, Clone)]
pub enum ApplyEvent {
Change(Change),
RelationChange(Box<RelationChange>),
}
impl ApplyEvent {
pub fn change(change: Change) -> Self {
Self::Change(change)
}
pub fn relation_change(change: RelationChange) -> Self {
Self::RelationChange(Box::new(change))
}
pub fn is_change(&self) -> bool {
matches!(self, Self::Change(_))
}
pub fn is_relation_change(&self) -> bool {
matches!(self, Self::RelationChange(_))
}
}
#[derive(Debug, Clone)]
pub struct PositionedEvent<P> {
pub event: ApplyEvent,
pub position: P,
}
impl<P> PositionedEvent<P> {
pub fn new(event: ApplyEvent, position: P) -> Self {
Self { event, position }
}
pub fn change(change: Change, position: P) -> Self {
Self::new(ApplyEvent::Change(change), position)
}
pub fn relation_change(change: RelationChange, position: P) -> Self {
Self::new(ApplyEvent::relation_change(change), position)
}
}