Reorder a bit

This commit is contained in:
Steven Fackler 2021-04-05 19:04:34 -04:00
parent a8ac31aa0f
commit 50fa995cf9
2 changed files with 16 additions and 16 deletions

View File

@ -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<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
@ -71,16 +68,15 @@ pub trait GenericClient: private::Sealed {
/// Like `Client::transaction`.
async fn transaction(&mut self) -> Result<Transaction<'_>, 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<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
T: ?Sized + ToStatement + Sync + Send,
@ -152,6 +148,10 @@ impl GenericClient for Client {
async fn transaction(&mut self) -> Result<Transaction<'_>, 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<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
where
T: ?Sized + ToStatement + Sync + Send,
@ -235,4 +231,8 @@ impl GenericClient for Transaction<'_> {
async fn transaction<'a>(&'a mut self) -> Result<Transaction<'a>, Error> {
self.transaction().await
}
fn client(&self) -> &Client {
self.client()
}
}

View File

@ -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
}
}