Add a get_kind method to Pool (#1228)

This commit is contained in:
nitnelave 2021-11-23 02:00:00 +01:00 committed by GitHub
parent 8299687878
commit 5aef7d7801
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -1,7 +1,7 @@
use crate::error::Error;
use std::str::FromStr;
#[derive(Debug, Clone, Copy)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum AnyKind {
#[cfg(feature = "postgres")]
Postgres,

View file

@ -55,6 +55,8 @@
//! [`Pool::begin`].
use self::inner::SharedPool;
#[cfg(feature = "any")]
use crate::any::{Any, AnyKind};
use crate::connection::Connection;
use crate::database::Database;
use crate::error::Error;
@ -290,7 +292,7 @@ impl<DB: Database> Pool<DB> {
}
}
/// Shut down the connection pool, waiting for all connections to be gracefully closed.
/// Shut down the connection pool, waiting for all connections to be gracefully closed.
///
/// Upon `.await`ing this call, any currently waiting or subsequent calls to [Pool::acquire] and
/// the like will immediately return [Error::PoolClosed] and no new connections will be opened.
@ -337,6 +339,17 @@ impl<DB: Database> Pool<DB> {
}
}
#[cfg(feature = "any")]
impl Pool<Any> {
/// Returns the database driver currently in-use by this `Pool`.
///
/// Determined by the connection URI.
#[cfg(feature = "any")]
pub fn any_kind(&self) -> AnyKind {
self.0.connect_options.kind()
}
}
/// Returns a new [Pool] tied to the same shared connection pool.
impl<DB: Database> Clone for Pool<DB> {
fn clone(&self) -> Self {