tokio_postgres/
to_statement.rs
1use crate::to_statement::private::{Sealed, ToStatementType};
2use crate::Statement;
3
4mod private {
5 use crate::{Client, Error, Statement};
6
7 pub trait Sealed {}
8
9 pub enum ToStatementType<'a> {
10 Statement(&'a Statement),
11 Query(&'a str),
12 }
13
14 impl<'a> ToStatementType<'a> {
15 pub async fn into_statement(self, client: &Client) -> Result<Statement, Error> {
16 match self {
17 ToStatementType::Statement(s) => Ok(s.clone()),
18 ToStatementType::Query(s) => client.prepare(s).await,
19 }
20 }
21 }
22}
23
24pub trait ToStatement: Sealed {
31 #[doc(hidden)]
32 fn __convert(&self) -> ToStatementType<'_>;
33}
34
35impl ToStatement for Statement {
36 fn __convert(&self) -> ToStatementType<'_> {
37 ToStatementType::Statement(self)
38 }
39}
40
41impl Sealed for Statement {}
42
43impl ToStatement for str {
44 fn __convert(&self) -> ToStatementType<'_> {
45 ToStatementType::Query(self)
46 }
47}
48
49impl Sealed for str {}
50
51impl ToStatement for String {
52 fn __convert(&self) -> ToStatementType<'_> {
53 ToStatementType::Query(self)
54 }
55}
56
57impl Sealed for String {}