Skip to main content

AsyncFnFactory

Struct AsyncFnFactory 

Source
pub struct AsyncFnFactory<T> { /* private fields */ }
Expand description

An AsyncConnectionFactory built from closures returning [BoxFuture]s.

Implementations§

Source§

impl<T> AsyncFnFactory<T>

Source

pub fn new<F>(create: F) -> Self
where F: Fn() -> Pin<Box<dyn Future<Output = Result<T, FactoryError>> + Send + 'static>> + Send + Sync + 'static,

Builds a factory from a create closure returning a boxed future.

Source

pub fn with_validate<F>(self, f: F) -> Self
where F: for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Send + Sync + 'static,

Sets the liveness check.

Source

pub fn with_reset<F>(self, f: F) -> Self
where F: for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), FactoryError>> + Send + 'a>> + Send + Sync + 'static,

Sets the release-time reset.

Source

pub fn with_close<F>(self, f: F) -> Self
where F: for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), FactoryError>> + Send + 'a>> + Send + Sync + 'static,

Sets the disposal hook.

Source

pub fn with_is_fatal_error<F>(self, f: F) -> Self
where F: Fn(&(dyn Error + 'static)) -> bool + Send + Sync + 'static,

Sets the fatal-error classifier.

Trait Implementations§

Source§

impl<T> AsyncConnectionFactory<T> for AsyncFnFactory<T>
where T: Send + Sync,

Source§

fn create(&self) -> impl Future<Output = Result<T, FactoryError>> + Send

Opens a new connection.
Source§

async fn validate(&self, conn: &T) -> bool

A cheap liveness check. Defaults to true.
Source§

async fn reset(&self, conn: &T) -> Result<(), FactoryError>

Scrubs session state on release. Defaults to a no-op.
Source§

async fn close(&self, conn: &T) -> Result<(), FactoryError>

Disposes of a connection. Defaults to a no-op.
Source§

fn is_fatal_error(&self, err: &(dyn Error + 'static)) -> bool

Whether err proves the connection is broken. Defaults to false.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for AsyncFnFactory<T>

§

impl<T> !UnwindSafe for AsyncFnFactory<T>

§

impl<T> Freeze for AsyncFnFactory<T>
where Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error + Sync + Send>>> + Send>> + Sync + Send>: Freeze, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Sync + Send>>: Freeze, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Freeze, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Freeze,

§

impl<T> Send for AsyncFnFactory<T>
where Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error + Sync + Send>>> + Send>> + Sync + Send>: Send, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Sync + Send>>: Send, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Send, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Send,

§

impl<T> Sync for AsyncFnFactory<T>
where Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error + Sync + Send>>> + Send>> + Sync + Send>: Sync, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Sync + Send>>: Sync, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Sync, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Sync,

§

impl<T> Unpin for AsyncFnFactory<T>
where Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error + Sync + Send>>> + Send>> + Sync + Send>: Unpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Sync + Send>>: Unpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Unpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: Unpin,

§

impl<T> UnsafeUnpin for AsyncFnFactory<T>
where Box<dyn Fn() -> Pin<Box<dyn Future<Output = Result<T, Box<dyn Error + Sync + Send>>> + Send>> + Sync + Send>: UnsafeUnpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = bool> + Send + 'a>> + Sync + Send>>: UnsafeUnpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: UnsafeUnpin, Option<Box<dyn for<'a> Fn(&'a T) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn Error + Sync + Send>>> + Send + 'a>> + Sync + Send>>: UnsafeUnpin,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.