From 8cae077ba1d54b92cdef3e171a730b819d5eeb8e Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Mon, 30 Aug 2021 04:02:13 -0700 Subject: [PATCH] Add 'Connection::into_inner()' in 'db_pools'. Resolves #1790. --- contrib/db_pools/lib/src/database.rs | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/contrib/db_pools/lib/src/database.rs b/contrib/db_pools/lib/src/database.rs index e6a21c76..8b67706f 100644 --- a/contrib/db_pools/lib/src/database.rs +++ b/contrib/db_pools/lib/src/database.rs @@ -214,6 +214,37 @@ impl Initializer { } } +impl Connection { + /// Returns the internal connection value. See the [`Connection` Deref + /// column](crate#supported-drivers) for the expected type of this value. + /// + /// Note that `Connection` derefs to the internal connection type, so + /// using this method is likely unnecessary. See [deref](Connection#deref) + /// for examples. + /// + /// # Example + /// + /// ```rust + /// # #[cfg(feature = "sqlx_sqlite")] mod _inner { + /// # use rocket::get; + /// # type Pool = rocket_db_pools::sqlx::SqlitePool; + /// use rocket_db_pools::{Database, Connection}; + /// + /// #[derive(Database)] + /// #[database("db")] + /// struct Db(Pool); + /// + /// #[get("/")] + /// async fn db_op(db: Connection) { + /// let inner = db.into_inner(); + /// } + /// # } + /// ``` + pub fn into_inner(self) -> ::Connection { + self.0 + } +} + #[rocket::async_trait] impl Fairing for Initializer { fn info(&self) -> Info {