Prevayler

Struct Prevayler 

Source
pub struct Prevayler<D, T, S> { /* private fields */ }
Expand description

The main Prevayler struct. This wrapper your data and save each executed transaction to the redolog. Avoid creating it directly. Use PrevaylerBuilder instead.

Implementations§

Source§

impl<D, T, S> Prevayler<D, T, S>

Source

pub async fn execute_transaction<TR>( &mut self, transaction: TR, ) -> PrevaylerResult<()>
where TR: Into<D>, D: Transaction<T>, S: Serializer<D>,

Execute the given transaction and write it to the redolog. You need to have a mutable reference to the prevayler. If you are in a multithread program, you can wrapp the prevayler behind a Mutex, RwLock or anyother concurrency control system.

This method returns a PrevaylerResult. If it the error is returned a PrevaylerError::SerializationError, then you can guarantee that the prevailed state did not change. But, if it returns the error a PrevaylerError::IOError, than the data did change but the redolog is in a inconsistent state. A solution would be to force a program restart.

Source

pub async fn execute_transaction_with_query<TR, R>( &mut self, transaction: TR, ) -> PrevaylerResult<R>
where TR: TransactionWithQuery<T, Output = R> + Into<D>, S: Serializer<D>,

Similar to the execute_transaction. But this execute TransactionWithQuery and returns its result.

Source

pub async fn execute_transaction_panic_safe<TR>( &mut self, transaction: TR, ) -> PrevaylerResult<()>
where TR: Into<D>, D: Transaction<T>, S: Serializer<D>, T: Clone,

Like execute_transaction, it executes the give transaction and write it to the redolog. But, if a transaction panics for some reason, this gurantees that the prevailed state will not be changed. This gurantee comes wiht a cost. The entire prevailed state is cloned everytime that a transaction is executed.

Think twice before using this method. Your transactions should probably not be able to panic. Try to do any code that can fail before the transaction and only do the state change inside it.

Source

pub async fn snapshot(&mut self) -> PrevaylerResult<()>
where S: Serializer<T>,

Does a snapshot of the prevailed state. This requires that the Serializer know how to serialize the prevailed state.

Source

pub fn query(&self) -> &T

Returns a reference to the prevailed state.

Auto Trait Implementations§

§

impl<D, T, S> Freeze for Prevayler<D, T, S>
where T: Freeze, S: Freeze,

§

impl<D, T, S> !RefUnwindSafe for Prevayler<D, T, S>

§

impl<D, T, S> Send for Prevayler<D, T, S>
where T: Send, S: Send, D: Send,

§

impl<D, T, S> Sync for Prevayler<D, T, S>
where T: Sync, S: Sync, D: Sync,

§

impl<D, T, S> Unpin for Prevayler<D, T, S>
where T: Unpin, S: Unpin, D: Unpin,

§

impl<D, T, S> !UnwindSafe for Prevayler<D, T, S>

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.