pub struct Recorder<T: Storage> { /* private fields */ }
Expand description

Persists records asynchronously.

You may want to use this instead of directly calling your persistence backend if you do not want to wait for the record to be persisted, in the handler which created the record. To achieve this Recoder spawns an actor to which all records are sent immediatly. The actor when uses the Storage trait to talk to your persistence backend.

Recorder takes ownership of an actor and the green thread it is running in.

Implementations§

source§

impl<T> Recorder<T>where T: Storage + 'static + Send, T::Record: Send, T::Query: Send,

source

pub async fn new(storage: T) -> Self

source

pub fn save(&self, record: T::Record)

Sends the record to the internal actor for storage. This interface is fire and forget. It will not wait for the record to be actually persisted, just place it in the channel for the actor to pick up. This is why this method is both synchronous and non blocking.

source

pub async fn close(self) -> T

Stop accepting new records to save, persist the ones send so far.

Gives back ownership of the underlying storage.

source

pub async fn records(&self, query: T::Query) -> Vec<T::Record>

All the records stored in the internal storage.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Recorder<T>

§

impl<T> Send for Recorder<T>where T: Send, <T as Storage>::Query: Send, <T as Storage>::Record: Send,

§

impl<T> Sync for Recorder<T>where T: Send, <T as Storage>::Query: Send, <T as Storage>::Record: Send,

§

impl<T> Unpin for Recorder<T>

§

impl<T> !UnwindSafe for Recorder<T>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.