Skip to main content

ReceivePersistent

Struct ReceivePersistent 

Source
pub struct ReceivePersistent<S, E, Err>
where S: Default + Send + 'static, E: Clone + Send + 'static, Err: Error + Send + 'static,
{ /* private fields */ }
Expand description

Closure-style persistent actor.

Implementations§

Source§

impl<S, E, Err> ReceivePersistent<S, E, Err>
where S: Default + Send + 'static, E: Clone + Send + 'static, Err: Error + Send + 'static,

Source

pub fn new(persistence_id: impl Into<String>) -> Self

Source

pub fn on_command<F>(self, f: F) -> Self
where F: FnMut(&S, E) -> Result<Vec<E>, Err> + Send + 'static,

Register the command handler. The closure receives the current state + the incoming command (the command type matches the event type for this minimal helper; richer command-vs-event shapes use Eventsourced directly).

Source

pub fn on_event<F>(self, f: F) -> Self
where F: FnMut(&mut S, &E) + Send + 'static,

Register the event applier — mutates state in-place.

Source

pub fn with_codec<EncF, DecF>(self, encode: EncF, decode: DecF) -> Self
where EncF: Fn(&E) -> Result<Vec<u8>, String> + Send + Sync + 'static, DecF: Fn(&[u8]) -> Result<E, String> + Send + Sync + 'static,

Register the codec used to round-trip events through the journal.

Source

pub fn state(&self) -> &S

Source

pub fn persistence_id(&self) -> &str

Source

pub async fn recover<J: Journal>( &mut self, journal: Arc<J>, permitter: &RecoveryPermitter, ) -> Result<u64, EventsourcedError<Err>>

Replay the journal under permitter and apply each event.

Source

pub async fn handle<J: Journal>( &mut self, journal: Arc<J>, cmd: E, ) -> Result<(), EventsourcedError<Err>>

Apply one command — derive events, persist, apply.

Auto Trait Implementations§

§

impl<S, E, Err> Freeze for ReceivePersistent<S, E, Err>
where S: Freeze,

§

impl<S, E, Err> !RefUnwindSafe for ReceivePersistent<S, E, Err>

§

impl<S, E, Err> Send for ReceivePersistent<S, E, Err>

§

impl<S, E, Err> !Sync for ReceivePersistent<S, E, Err>

§

impl<S, E, Err> Unpin for ReceivePersistent<S, E, Err>
where S: Unpin,

§

impl<S, E, Err> UnsafeUnpin for ReceivePersistent<S, E, Err>
where S: UnsafeUnpin,

§

impl<S, E, Err> !UnwindSafe for ReceivePersistent<S, E, Err>

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, 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, 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.