diff --git a/tokio-postgres/src/generic_client.rs b/tokio-postgres/src/generic_client.rs index 911a587b..b2a90755 100644 --- a/tokio-postgres/src/generic_client.rs +++ b/tokio-postgres/src/generic_client.rs @@ -12,9 +12,6 @@ mod private { /// This trait is "sealed", and cannot be implemented outside of this crate. #[async_trait] pub trait GenericClient: private::Sealed { - /// Get a reference to the underlying `Client` - fn client(&self) -> &Client; - /// Like `Client::execute`. async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where @@ -71,16 +68,15 @@ pub trait GenericClient: private::Sealed { /// Like `Client::transaction`. async fn transaction(&mut self) -> Result, Error>; + + /// Returns a reference to the underlying `Client`. + fn client(&self) -> &Client; } impl private::Sealed for Client {} #[async_trait] impl GenericClient for Client { - fn client(&self) -> &Client { - self - } - async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where T: ?Sized + ToStatement + Sync + Send, @@ -152,6 +148,10 @@ impl GenericClient for Client { async fn transaction(&mut self) -> Result, Error> { self.transaction().await } + + fn client(&self) -> &Client { + self + } } impl private::Sealed for Transaction<'_> {} @@ -159,10 +159,6 @@ impl private::Sealed for Transaction<'_> {} #[async_trait] #[allow(clippy::needless_lifetimes)] impl GenericClient for Transaction<'_> { - fn client(&self) -> &Client { - self.client() - } - async fn execute(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result where T: ?Sized + ToStatement + Sync + Send, @@ -235,4 +231,8 @@ impl GenericClient for Transaction<'_> { async fn transaction<'a>(&'a mut self) -> Result, Error> { self.transaction().await } + + fn client(&self) -> &Client { + self.client() + } } diff --git a/tokio-postgres/src/transaction.rs b/tokio-postgres/src/transaction.rs index cf39d918..7fadce06 100644 --- a/tokio-postgres/src/transaction.rs +++ b/tokio-postgres/src/transaction.rs @@ -64,11 +64,6 @@ impl<'a> Transaction<'a> { } } - /// Get a reference to the underlying `Client` - pub fn client(&self) -> &Client { - &self.client - } - /// Consumes the transaction, committing all changes made within it. pub async fn commit(mut self) -> Result<(), Error> { self.done = true; @@ -311,4 +306,9 @@ impl<'a> Transaction<'a> { done: false, }) } + + /// Returns a reference to the underlying `Client`. + pub fn client(&self) -> &Client { + &self.client + } }