[−][src]Struct tang_rs::Pool
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]
F: FnOnce(&mut M::Connection) -> Pin<Box<dyn Future<Output = Result<T, E>> + Send>>,
E: From<M::Error>,
T: Send + 'static,
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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<M: Manager + Send> Debug for Pool<M>
[src]
Auto Trait Implementations
impl<M> RefUnwindSafe for Pool<M> where
M: RefUnwindSafe,
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,
M: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,