Trait Manager

Source
pub trait Manager:
    Sized
    + Send
    + Sync
    + 'static {
    type Connection: Unpin + 'static;
    type Error: Debug + From<Self::TimeoutError> + 'static;
    type Timeout: Future<Output = Self::TimeoutError> + Send;
    type TimeoutError: Send + Debug + 'static;

    // Required methods
    fn connect(
        &self,
    ) -> ManagerFuture<'_, Result<Self::Connection, Self::Error>>;
    fn is_valid<'a>(
        &'a self,
        conn: &'a mut Self::Connection,
    ) -> ManagerFuture<'a, Result<(), Self::Error>>;
    fn is_closed(&self, conn: &mut Self::Connection) -> bool;
    fn spawn<Fut>(&self, fut: Fut)
       where Fut: Future<Output = ()> + Send + 'static;
    fn timeout<Fut: Future>(
        &self,
        fut: Fut,
        _dur: Duration,
    ) -> ManagerTimeout<Fut, Self::Timeout> ;

    // Provided methods
    fn on_start(&self, _shared_pool: &SharedManagedPool<Self>) { ... }
    fn on_stop(&self) { ... }
}
Expand description

§Types for different runtimes:

Trait type runtime Type constructor Manager::Timeout tokio tokio::time::Delay tokio::time::delay_for async-std smol::Timer smol::Timer::after

Manager::TimeoutError tokio () async-std std::time::Instant

Required Associated Types§

Source

type Connection: Unpin + 'static

Source

type Error: Debug + From<Self::TimeoutError> + 'static

Source

type Timeout: Future<Output = Self::TimeoutError> + Send

Source

type TimeoutError: Send + Debug + 'static

Required Methods§

Source

fn connect(&self) -> ManagerFuture<'_, Result<Self::Connection, Self::Error>>

generate a new connection and put it into pool.

Source

fn is_valid<'a>( &'a self, conn: &'a mut Self::Connection, ) -> ManagerFuture<'a, Result<(), Self::Error>>

check if a connection is valid.

*. Only called when Builder.always_check == true

Source

fn is_closed(&self, conn: &mut Self::Connection) -> bool

check if a connection is closed.

This happens before a connection put back to pool.

Source

fn spawn<Fut>(&self, fut: Fut)
where Fut: Future<Output = ()> + Send + 'static,

spawn futures on your executor

The future have to be Send + 'static and the return type(e.g. JoinHandler) of your executor will be ignored.

Source

fn timeout<Fut: Future>( &self, fut: Fut, _dur: Duration, ) -> ManagerTimeout<Fut, Self::Timeout>

Used to cancel futures and return Manager::TimeoutError.

The duration is determined by Builder.wait_timeout and Builder.connection_timeout

Provided Methods§

Source

fn on_start(&self, _shared_pool: &SharedManagedPool<Self>)

This method will be called when Pool<Manager>::init() executes.

Source

fn on_stop(&self)

This method will be called when Pool<Manager> is dropping

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§