Skip to main content

FnFactory

Struct FnFactory 

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

A ConnectionFactory built from plain closures. Unset hooks fall back to the trait defaults.

Implementations§

Source§

impl<T> FnFactory<T>

Source

pub fn new<F>(create: F) -> Self
where F: Fn() -> Result<T, FactoryError> + Send + Sync + 'static,

Builds a factory from a create closure.

Source

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

Sets the liveness check.

Source

pub fn with_reset<F>(self, f: F) -> Self
where F: Fn(&T) -> Result<(), FactoryError> + Send + Sync + 'static,

Sets the release-time reset.

Source

pub fn with_close<F>(self, f: F) -> Self
where F: Fn(&T) -> Result<(), FactoryError> + 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> ConnectionFactory<T> for FnFactory<T>
where T: Send + Sync,

Source§

fn create(&self) -> Result<T, FactoryError>

Opens a new connection. Should enforce its own connect timeout.
Source§

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

A cheap liveness check (e.g. SELECT 1). false = dead. Defaults to true.
Source§

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

Called on release to scrub session state (e.g. rollback). Defaults to a no-op.
Source§

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

Disposes of a connection. Defaults to a no-op — most Rust connections close on Drop; override only when explicit teardown is needed.
Source§

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

Whether err (raised by user code using the connection) proves the connection is broken, so it is discarded without further checks. Defaults to false.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for FnFactory<T>

§

impl<T> !UnwindSafe for FnFactory<T>

§

impl<T> Freeze for FnFactory<T>
where Box<dyn Fn() -> Result<T, Box<dyn Error + Send + Sync>> + Send + Sync>: Freeze, Option<Box<dyn Fn(&T) -> bool + Send + Sync>>: Freeze, Option<Box<dyn Fn(&T) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync>>: Freeze,

§

impl<T> Send for FnFactory<T>
where Box<dyn Fn() -> Result<T, Box<dyn Error + Send + Sync>> + Send + Sync>: Send, Option<Box<dyn Fn(&T) -> bool + Send + Sync>>: Send, Option<Box<dyn Fn(&T) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync>>: Send,

§

impl<T> Sync for FnFactory<T>
where Box<dyn Fn() -> Result<T, Box<dyn Error + Send + Sync>> + Send + Sync>: Sync, Option<Box<dyn Fn(&T) -> bool + Send + Sync>>: Sync, Option<Box<dyn Fn(&T) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync>>: Sync,

§

impl<T> Unpin for FnFactory<T>
where Box<dyn Fn() -> Result<T, Box<dyn Error + Send + Sync>> + Send + Sync>: Unpin, Option<Box<dyn Fn(&T) -> bool + Send + Sync>>: Unpin, Option<Box<dyn Fn(&T) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync>>: Unpin,

§

impl<T> UnsafeUnpin for FnFactory<T>
where Box<dyn Fn() -> Result<T, Box<dyn Error + Send + Sync>> + Send + Sync>: UnsafeUnpin, Option<Box<dyn Fn(&T) -> bool + Send + Sync>>: UnsafeUnpin, Option<Box<dyn Fn(&T) -> Result<(), Box<dyn Error + Send + Sync>> + Send + Sync>>: 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.