[][src]Struct tang_rs::Pool

pub struct Pool<M: Manager + Send>(_);

Methods

impl<M: Manager + Send> Pool<M>[src]

pub async fn init<'_>(&'_ self) -> Result<(), M::Error>[src]

manually initialize pool. this is usually called when the Pool is built with build_uninitialized This is useful when you want to make a empty Pool and init it later.

example:

This example is not tested
#[macro_use]
extern crate lazy_static;

use tang_rs::{Pool, PostgresManager, Builder};
use tokio_postgres::NoTls;

lazy_static! {
   static ref POOL: Pool<PostgresManager<NoTls>> = Builder::new()
        .always_check(false)
        .idle_timeout(None)
        .max_lifetime(None)
        .min_idle(24)
        .max_size(24)
        .build_uninitialized(
            PostgresManager::new_from_stringlike("postgres://postgres:123@localhost/test", NoTls)
                .expect("can't make postgres manager")
        )
        .unwrap_or_else(|e| panic!("{:?}", e));
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    POOL.init().await.expect("Failed to initialize postgres pool");
    Ok(())
}

pub async fn get<'_, '_>(&'_ self) -> Result<PoolRef<'_, M>, M::Error>[src]

Return a reference of Arc<SharedPool<Manager>> and a Option<Manager::Connection>. The PoolRef should be drop asap when you finish the use of it.

pub async fn run<'_, T, E, F>(&'_ self, f: F) -> Result<T, E> where
    F: FnOnce(&mut M::Connection) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send>>,
    E: From<M::Error>,
    T: Send + 'static, 
[src]

Run the pool with a closure. Usually slightly faster than Pool.get() as we only do conditional broken check according to the closure result.

pub fn get_manager(&self) -> &M[src]

pub fn state(&self) -> State[src]

Return a state of the pool inner. This call will block the thread and wait for lock.

Trait Implementations

impl<M: Manager + Send> Clone for Pool<M>[src]

impl<M: Manager + Send> Debug for Pool<M>[src]

Auto Trait Implementations

impl<M> RefUnwindSafe for Pool<M> where
    M: RefUnwindSafe

impl<M> Send for Pool<M>

impl<M> Sync for Pool<M>

impl<M> Unpin for Pool<M>

impl<M> UnwindSafe for Pool<M> where
    M: RefUnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.