Struct prevayler_rs::Prevayler[][src]

pub struct Prevayler<D, T, S> { /* fields omitted */ }

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

Implementations

impl<D, T, S> Prevayler<D, T, S>[src]

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

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.

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>, 
[src]

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

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
[src]

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.

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

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

pub fn query(&self) -> &T[src]

Returns a reference to the prevailed state.

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.