pub struct Segment<'a, T>{ /* private fields */ }
Expand description
A segment is a part of an event log.
It’s a list of events followed by a projection, called a “snapshot”. Creating a new segment will make the former segments snapshot immutable, and a new (mutable) segment is created.
Snapshots allow for faster history traversal, as not the entire event log needs to be replayed in order to project an earlier state, unlike a single-segment event log.
Implementations§
Source§impl<'a, T> Segment<'a, T>
impl<'a, T> Segment<'a, T>
Sourcepub fn new() -> Segment<'a, T>
pub fn new() -> Segment<'a, T>
Creates a new segment
The new segment will have a timestamp of the current time, and won’t have any prior history associated with it.
Sourcepub fn from_projection(
projection: Vec<Cow<'a, T>>,
events: Vec<Event<'a, T>>,
) -> Segment<'a, T>
pub fn from_projection( projection: Vec<Cow<'a, T>>, events: Vec<Event<'a, T>>, ) -> Segment<'a, T>
Creates a new segment from a given projection and event log at the current time
Sourcepub fn get_time(&self) -> &Timestamp
pub fn get_time(&self) -> &Timestamp
Returns a shared reference to the timestamp of this segment
Sourcepub fn get_projection(&self) -> &Vec<Cow<'a, T>>
pub fn get_projection(&self) -> &Vec<Cow<'a, T>>
Returns the current projection
Sourcepub fn project_at_onto(
&self,
timestamp: &Timestamp,
snapshot: Vec<Cow<'a, T>>,
) -> Option<Vec<Cow<'a, T>>>
pub fn project_at_onto( &self, timestamp: &Timestamp, snapshot: Vec<Cow<'a, T>>, ) -> Option<Vec<Cow<'a, T>>>
Projects the segments events predating a specified timestamp onto a given snapshot
Sourcepub fn push(&mut self, event: Event<'a, T>) -> Result<()>
pub fn push(&mut self, event: Event<'a, T>) -> Result<()>
Applies and appends an event to the segments snapshot and log, respectively (checked)
Sourcepub fn prepend(&mut self, other: Self) -> Result<()>
pub fn prepend(&mut self, other: Self) -> Result<()>
Merges two consecutive segments by prepending the other before this one (checked)
Sourcepub fn prepend_unchecked(&mut self, other: Self)
pub fn prepend_unchecked(&mut self, other: Self)
Merges two consecutive segments by prepending the other before this one (unchecked)