DatabaseAsync

Struct DatabaseAsync 

Source
pub struct DatabaseAsync<S> { /* private fields */ }
Expand description

This is an async wrapper for Database.

You can easily achieve the same thing with tokio::task::spawn_blocking, but this wrapper is a little bit more efficient while also being runtime agnostic.

Implementations§

Source§

impl<S: 'static + Send + Sync + Schema> DatabaseAsync<S>

Source

pub fn new(db: Arc<Database<S>>) -> Self

Create an async wrapper for the Database.

The database is wrapped in an Arc as it needs to be shared with any thread executing a transaction. These threads can live longer than the future that started the transaction.

By accepting an Arc, you can keep your own clone of the Arc and use the database synchronously and asynchronously at the same time!

Source

pub async fn transaction<R: 'static + Send>( &self, f: impl 'static + Send + FnOnce(&'static Transaction<S>) -> R, ) -> R

This is a lot like Database::transaction, the only difference is that the async function does not block the runtime and requires the closure to be 'static. The static requirement is because the future may be canceled, but the transaction can not be canceled.

Source

pub async fn transaction_mut<O: 'static + Send, E: 'static + Send>( &self, f: impl 'static + Send + FnOnce(&'static mut Transaction<S>) -> Result<O, E>, ) -> Result<O, E>

This is a lot like Database::transaction_mut, the only difference is that the async function does not block the runtime and requires the closure to be 'static. The static requirement is because the future may be canceled, but the transaction can not be canceled.

Source

pub async fn transaction_mut_ok<R: 'static + Send>( &self, f: impl 'static + Send + FnOnce(&'static mut Transaction<S>) -> R, ) -> R

This is a lot like Database::transaction_mut_ok, the only difference is that the async function does not block the runtime and requires the closure to be 'static. The static requirement is because the future may be canceled, but the transaction can not be canceled.

Trait Implementations§

Source§

impl<S> Clone for DatabaseAsync<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<S> Freeze for DatabaseAsync<S>

§

impl<S> !RefUnwindSafe for DatabaseAsync<S>

§

impl<S> Send for DatabaseAsync<S>
where S: Sync + Send,

§

impl<S> Sync for DatabaseAsync<S>
where S: Sync + Send,

§

impl<S> Unpin for DatabaseAsync<S>

§

impl<S> !UnwindSafe for DatabaseAsync<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V