Line data Source code
1 : #![allow(async_fn_in_trait)]
2 :
3 : use crate::query::RowStream;
4 : use crate::{Client, Error, Transaction};
5 :
6 : mod private {
7 : pub trait Sealed {}
8 : }
9 :
10 : /// A trait allowing abstraction over connections and transactions.
11 : ///
12 : /// This trait is "sealed", and cannot be implemented outside of this crate.
13 : pub trait GenericClient: private::Sealed {
14 : /// Like `Client::query_raw_txt`.
15 : async fn query_raw_txt<S, I>(&mut self, statement: &str, params: I) -> Result<RowStream, Error>
16 : where
17 : S: AsRef<str> + Sync + Send,
18 : I: IntoIterator<Item = Option<S>> + Sync + Send,
19 : I::IntoIter: ExactSizeIterator + Sync + Send;
20 : }
21 :
22 : impl private::Sealed for Client {}
23 :
24 : impl GenericClient for Client {
25 0 : async fn query_raw_txt<S, I>(&mut self, statement: &str, params: I) -> Result<RowStream, Error>
26 0 : where
27 0 : S: AsRef<str> + Sync + Send,
28 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
29 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
30 0 : {
31 0 : self.query_raw_txt(statement, params).await
32 0 : }
33 : }
34 :
35 : impl private::Sealed for Transaction<'_> {}
36 :
37 : impl GenericClient for Transaction<'_> {
38 0 : async fn query_raw_txt<S, I>(&mut self, statement: &str, params: I) -> Result<RowStream, Error>
39 0 : where
40 0 : S: AsRef<str> + Sync + Send,
41 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
42 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
43 0 : {
44 0 : self.query_raw_txt(statement, params).await
45 0 : }
46 : }
|