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>(
16 : &mut self,
17 : statement: &str,
18 : params: I,
19 : ) -> Result<RowStream<'_>, Error>
20 : where
21 : S: AsRef<str> + Sync + Send,
22 : I: IntoIterator<Item = Option<S>> + Sync + Send,
23 : I::IntoIter: ExactSizeIterator + Sync + Send;
24 : }
25 :
26 : impl private::Sealed for Client {}
27 :
28 : impl GenericClient for Client {
29 0 : async fn query_raw_txt<S, I>(
30 0 : &mut self,
31 0 : statement: &str,
32 0 : params: I,
33 0 : ) -> Result<RowStream<'_>, Error>
34 0 : where
35 0 : S: AsRef<str> + Sync + Send,
36 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
37 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
38 0 : {
39 0 : self.query_raw_txt(statement, params).await
40 0 : }
41 : }
42 :
43 : impl private::Sealed for Transaction<'_> {}
44 :
45 : impl GenericClient for Transaction<'_> {
46 0 : async fn query_raw_txt<S, I>(
47 0 : &mut self,
48 0 : statement: &str,
49 0 : params: I,
50 0 : ) -> Result<RowStream<'_>, Error>
51 0 : where
52 0 : S: AsRef<str> + Sync + Send,
53 0 : I: IntoIterator<Item = Option<S>> + Sync + Send,
54 0 : I::IntoIter: ExactSizeIterator + Sync + Send,
55 0 : {
56 0 : self.query_raw_txt(statement, params).await
57 0 : }
58 : }
|