pub struct StreamHistory<E> { /* private fields */ }Expand description
English:
Non-empty, complete history in replay order starting at revision 0.
Construction checks event count against the final revision, not event contents or identity.
日本語:
リビジョン 0 から始まる再生順の空でない完全な履歴です。
構築時にはイベント数と最終リビジョンを照合し、内容や識別子は検証しません。
§Example / 使用例
use ddd_toolkit_core::{StreamHistory, StreamRevision};
let history = StreamHistory::try_new(vec!["created", "updated"], StreamRevision::new(1))?;
assert_eq!(history.events_after(StreamRevision::new(0)), Some(&["updated"][..]));
assert_eq!(history.events_after(StreamRevision::new(1)), Some(&[][..]));Implementations§
Source§impl<E> StreamHistory<E>
impl<E> StreamHistory<E>
Sourcepub fn try_new(
events: Vec<E>,
revision: StreamRevision,
) -> Result<StreamHistory<E>, StreamHistoryError>
pub fn try_new( events: Vec<E>, revision: StreamRevision, ) -> Result<StreamHistory<E>, StreamHistoryError>
English:
Takes ownership of events and checks that revision equals their count minus one.
Returns StreamHistoryError::Empty for no events, StreamHistoryError::TooManyEvents
if the count cannot fit in u64, or StreamHistoryError::RevisionMismatch for a mismatch.
日本語:
イベントを所有し、revision がイベント数から 1 を引いた値か確認します。
空なら StreamHistoryError::Empty、件数が u64 に収まらなければ
StreamHistoryError::TooManyEvents、不一致なら StreamHistoryError::RevisionMismatch を返します。
Sourcepub fn events(&self) -> &[E]
pub fn events(&self) -> &[E]
English:
Borrows all events in construction order.
日本語:
構築時の順序ですべてのイベントを借用します。
Sourcepub fn revision(&self) -> StreamRevision
pub fn revision(&self) -> StreamRevision
English:
Returns the final event’s revision.
日本語:
最後のイベントのリビジョンを返します。
Sourcepub fn into_events(self) -> Vec<E>
pub fn into_events(self) -> Vec<E>
English:
Consumes the history and returns its events without cloning.
日本語:
履歴を消費し、複製せずにイベントを返します。
Sourcepub fn events_after(&self, revision: StreamRevision) -> Option<&[E]>
pub fn events_after(&self, revision: StreamRevision) -> Option<&[E]>
English:
Borrows events strictly after revision; the final revision yields an empty slice.
Returns None for a future revision or if the next index cannot fit in usize.
日本語:
revision より後のイベントを借用します。最終リビジョンなら空スライスです。
未来のリビジョンや、次の添字が usize に収まらない場合は None を返します。