Skip to main content

Entity

Struct Entity 

Source
pub struct Entity { /* private fields */ }

Implementations§

Source§

impl Entity

Source

pub fn new() -> Self

Source

pub fn with_id(id: impl Into<String>) -> Self

Source

pub fn id(&self) -> &str

Source

pub fn set_id(&mut self, id: impl Into<String>)

Source

pub fn version(&self) -> u64

Source

pub fn snapshot_version(&self) -> u64

Source

pub fn set_snapshot_version(&mut self, snapshot_version: u64)

Source

pub fn committed_version(&self) -> u64

Source

pub fn events(&self) -> &[EventRecord]

Source

pub fn take_events(&mut self) -> Vec<EventRecord>

Take the in-memory events out of the entity, leaving it empty.

Used by replay paths that need to iterate events while also holding a mutable borrow of the owning aggregate (the borrow checker forbids borrowing events immutably and the aggregate mutably at once). The caller is responsible for restoring history afterward — e.g. via load_from_history — so the entity’s version/committed_version invariants hold.

Source

pub fn restore_history(&mut self, events: Vec<EventRecord>)

Put a previously taken event history back without recomputing version/prefix_version/committed_version. The caller must restore the same events the entity already accounted for, so the existing invariants continue to hold (used by replay paths that only borrowed the events out to satisfy the borrow checker).

Source

pub fn new_events(&self) -> &[EventRecord]

Returns events added since the entity was loaded (not yet persisted).

Slices relative to prefix_version so it is correct whether the entity holds the full history (prefix_version == 0) or only a snapshot tail.

Source

pub fn mark_committed(&mut self)

Mark all current events as committed. Called by repository after successful commit.

Source

pub fn set_metadata(&mut self, metadata: HashMap<String, String>)

Set metadata that will be attached to every subsequent event.

Call this before invoking command methods to propagate context (correlation IDs, user info, trace spans) into the event stream.

Source

pub fn set_meta(&mut self, key: impl Into<String>, value: impl Into<String>)

Set a single metadata key-value pair.

Source

pub fn set_correlation_id(&mut self, id: impl Into<String>)

Set the correlation ID for subsequent events.

Source

pub fn set_causation_id(&mut self, id: impl Into<String>)

Set the causation ID for subsequent events.

Source

pub fn metadata(&self) -> &HashMap<String, String>

Get the current metadata context.

Source

pub fn clear_metadata(&mut self)

Clear all metadata.

Source

pub fn digest<T: Serialize>( &mut self, name: impl Into<String>, payload: &T, ) -> SourcedResult

Record an event with a serializable payload.

If serialization fails, the entity is left unchanged. Any metadata set on the entity is attached to the event.

Source

pub fn digest_v<T: Serialize>( &mut self, name: impl Into<String>, version: u64, payload: &T, ) -> SourcedResult

Record a versioned event.

If serialization fails, the entity is left unchanged.

Source

pub fn digest_empty(&mut self, name: impl Into<String>) -> SourcedResult

Record an event with no payload.

Source

pub fn load_from_history(&mut self, history: Vec<EventRecord>)

Source

pub fn load_tail_from_history( &mut self, tail: Vec<EventRecord>, prefix_version: u64, )

Load only the tail of a stream — the events after a known prefix that is not held in memory (e.g. events already folded into a snapshot).

Unlike load_from_history, the in-memory events here are a suffix of the durable stream, so version and committed_version must be supplied explicitly rather than derived from events.len(). They reflect the true persisted stream position: committed_version is the optimistic-concurrency expected_version for the next commit, and new_events() slices relative to it.

§Invariant

prefix_version is the count of events covered by the omitted prefix. Callers must guarantee that every event in tail has sequence > prefix_version and that sequences are contiguous, so the resulting version == prefix_version + tail.len() equals the true max(sequence). Snapshots satisfy this: prefix_version is the snapshot version and the tail is exactly sequence > snapshot.version.

Source

pub fn rehydrate<F, E>(&mut self, apply: F) -> Result<(), E>
where F: FnMut(&EventRecord) -> Result<(), E>,

Source

pub fn is_replaying(&self) -> bool

Source

pub fn set_replaying(&mut self, replaying: bool)

Trait Implementations§

Source§

impl Clone for Entity

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Committable for Entity

Source§

fn entities_mut(&mut self) -> Vec<&mut Entity>

Returns mutable references to all entities to be committed.
Source§

impl Debug for Entity

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Entity

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Entity

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Entity

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateBuilder for T

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Queueable for T

Source§

fn queued(self) -> QueuedRepository<Self, InMemoryLockManager>

Wrap with the default async lock manager. Pair with .aggregate::<T>() for per-aggregate serialization over the async repository surface.
Source§

fn queued_with<L: LockManager>( self, lock_manager: L, ) -> QueuedRepository<Self, L>

Wrap with a custom async lock manager.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.