Skip to main content

EntityLog

Struct EntityLog 

Source
pub struct EntityLog { /* private fields */ }
Expand description

Local view of an entity’s event log.

Implementations§

Source§

impl EntityLog

Source

pub fn new(entity_id: EntityId) -> Self

Create a new empty log for an entity.

Source

pub fn from_snapshot( entity_id: EntityId, snapshot_seq: u64, head_link: CausalLink, head_payload: Bytes, ) -> Self

Create from a snapshot (for catchup — events after snapshot_seq will be appended).

Source

pub fn append(&mut self, event: CausalEvent) -> Result<(), LogError>

Append a causal event to the log.

Validates chain integrity (origin, sequence, parent_hash). Returns an error if the chain is broken.

Source

pub fn range(&self, from_seq: u64, to_seq: u64) -> Vec<&CausalEvent>

Get events in a sequence range (inclusive).

Source

pub fn after(&self, seq: u64) -> Vec<&CausalEvent>

Get all events after a given sequence.

Get the head (latest) link.

Source

pub fn head_seq(&self) -> u64

Get the head sequence number.

Source

pub fn entity_id(&self) -> &EntityId

Get the entity ID.

Source

pub fn origin_hash(&self) -> u64

Get the origin hash.

Source

pub fn len(&self) -> usize

Number of events in the log.

Source

pub fn is_empty(&self) -> bool

Check if the log is empty.

Source

pub fn prune_through(&mut self, seq: u64)

Prune events up to and including a sequence number.

Called after a snapshot is taken at that sequence.

snapshot_seq is only advanced when last_pruned.is_some() — i.e. a real event was actually pruned. The pruning side-effects (base_link, head_payload) only fire when at least one event is removed, so unconditionally bumping snapshot_seq whenever seq > self.snapshot_seq (even on an empty log, or when seq < first_event.sequence) would leave base_link.sequence behind, producing a permanent desync where head_seq().max(snapshot_seq()) returns a value the next append can’t agree with. Callers that need to install an externally-coordinated snapshot anchor on an empty log should use from_snapshot instead.

Source

pub fn snapshot_seq(&self) -> u64

Get the snapshot sequence (events before this have been pruned).

Trait Implementations§

Source§

impl Debug for EntityLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more