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