pub trait Eventsourced: Send + 'static {
type Command: Send + 'static;
type Event: Send + Clone + 'static;
type State: Default + Send + 'static;
type Error: Error + Send + 'static;
// Required methods
fn persistence_id(&self) -> String;
fn command_to_events(
&self,
state: &Self::State,
cmd: Self::Command,
) -> Result<Vec<Self::Event>, Self::Error>;
fn apply_event(state: &mut Self::State, event: &Self::Event);
fn encode_event(event: &Self::Event) -> Result<Vec<u8>, String>;
fn decode_event(bytes: &[u8]) -> Result<Self::Event, String>;
// Provided methods
fn event_manifest(&self) -> &'static str { ... }
fn recovery_completed<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_state: &'life1 Self::State,
_highest_seq: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn recover<'life0, 'life1, 'life2, 'async_trait, J>(
&'life0 mut self,
journal: Arc<J>,
state: &'life1 mut Self::State,
permitter: &'life2 RecoveryPermitter,
) -> Pin<Box<dyn Future<Output = Result<u64, EventsourcedError<Self::Error>>> + Send + 'async_trait>>
where J: 'async_trait + Journal,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
fn handle_command<'life0, 'life1, 'life2, 'life3, 'async_trait, J>(
&'life0 self,
journal: Arc<J>,
state: &'life1 mut Self::State,
next_seq: &'life2 mut u64,
writer_uuid: &'life3 str,
cmd: Self::Command,
) -> Pin<Box<dyn Future<Output = Result<(), EventsourcedError<Self::Error>>> + Send + 'async_trait>>
where J: 'async_trait + Journal,
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn save_snapshot<'life0, 'async_trait, S>(
&'life0 self,
store: Arc<S>,
sequence_nr: u64,
payload: Vec<u8>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where S: 'async_trait + SnapshotStore,
Self: Sync + 'async_trait,
'life0: 'async_trait { ... }
}Expand description
Modern event-sourced actor.
Required Associated Types§
Required Methods§
Sourcefn persistence_id(&self) -> String
fn persistence_id(&self) -> String
Stable journal key for this actor instance.
Sourcefn command_to_events(
&self,
state: &Self::State,
cmd: Self::Command,
) -> Result<Vec<Self::Event>, Self::Error>
fn command_to_events( &self, state: &Self::State, cmd: Self::Command, ) -> Result<Vec<Self::Event>, Self::Error>
Pure projection of a command into 0..N events. Validation /
rejection lives here (Err(_) aborts the persist).
Sourcefn apply_event(state: &mut Self::State, event: &Self::Event)
fn apply_event(state: &mut Self::State, event: &Self::Event)
Apply a persisted event to in-memory state. Called both during recovery (per replayed event) and during normal operation (after each successful persist).
Sourcefn encode_event(event: &Self::Event) -> Result<Vec<u8>, String>
fn encode_event(event: &Self::Event) -> Result<Vec<u8>, String>
Encode an event for the journal. Errors short-circuit the
persist with EventsourcedError::Codec.
Sourcefn decode_event(bytes: &[u8]) -> Result<Self::Event, String>
fn decode_event(bytes: &[u8]) -> Result<Self::Event, String>
Decode an event from journal bytes. Symmetric with
Self::encode_event.
Provided Methods§
Sourcefn event_manifest(&self) -> &'static str
fn event_manifest(&self) -> &'static str
Manifest tag baked into each PersistentRepr so cross-version
replay can dispatch to the right decoder. Defaults to "evt".
Sourcefn recovery_completed<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_state: &'life1 Self::State,
_highest_seq: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn recovery_completed<'life0, 'life1, 'async_trait>(
&'life0 mut self,
_state: &'life1 Self::State,
_highest_seq: u64,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Lifecycle hook fired after recovery completes. Default no-op.
Sourcefn recover<'life0, 'life1, 'life2, 'async_trait, J>(
&'life0 mut self,
journal: Arc<J>,
state: &'life1 mut Self::State,
permitter: &'life2 RecoveryPermitter,
) -> Pin<Box<dyn Future<Output = Result<u64, EventsourcedError<Self::Error>>> + Send + 'async_trait>>where
J: 'async_trait + Journal,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn recover<'life0, 'life1, 'life2, 'async_trait, J>(
&'life0 mut self,
journal: Arc<J>,
state: &'life1 mut Self::State,
permitter: &'life2 RecoveryPermitter,
) -> Pin<Box<dyn Future<Output = Result<u64, EventsourcedError<Self::Error>>> + Send + 'async_trait>>where
J: 'async_trait + Journal,
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Replay the journal under a RecoveryPermitter, applying
each event to state. Returns the highest replayed
sequence number.
Sourcefn handle_command<'life0, 'life1, 'life2, 'life3, 'async_trait, J>(
&'life0 self,
journal: Arc<J>,
state: &'life1 mut Self::State,
next_seq: &'life2 mut u64,
writer_uuid: &'life3 str,
cmd: Self::Command,
) -> Pin<Box<dyn Future<Output = Result<(), EventsourcedError<Self::Error>>> + Send + 'async_trait>>
fn handle_command<'life0, 'life1, 'life2, 'life3, 'async_trait, J>( &'life0 self, journal: Arc<J>, state: &'life1 mut Self::State, next_seq: &'life2 mut u64, writer_uuid: &'life3 str, cmd: Self::Command, ) -> Pin<Box<dyn Future<Output = Result<(), EventsourcedError<Self::Error>>> + Send + 'async_trait>>
Run a single command — derive events, persist, apply.
Sourcefn save_snapshot<'life0, 'async_trait, S>(
&'life0 self,
store: Arc<S>,
sequence_nr: u64,
payload: Vec<u8>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
S: 'async_trait + SnapshotStore,
Self: Sync + 'async_trait,
'life0: 'async_trait,
fn save_snapshot<'life0, 'async_trait, S>(
&'life0 self,
store: Arc<S>,
sequence_nr: u64,
payload: Vec<u8>,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
S: 'async_trait + SnapshotStore,
Self: Sync + 'async_trait,
'life0: 'async_trait,
Save a snapshot of current state under sequence_nr.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.