forked from sfackler/rust-postgres
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto_statement.rs
34 lines (27 loc) · 896 Bytes
/
to_statement.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use tokio_postgres::Error;
use crate::{Client, Statement};
mod sealed {
pub trait Sealed {}
}
/// A trait abstracting over prepared and unprepared statements.
///
/// Many methods are generic over this bound, so that they support both a raw query string as well as a statement which
/// was prepared previously.
///
/// This trait is "sealed" and cannot be implemented by anything outside this crate.
pub trait ToStatement: sealed::Sealed {
#[doc(hidden)]
fn __statement(&self, client: &mut Client) -> Result<Statement, Error>;
}
impl sealed::Sealed for str {}
impl ToStatement for str {
fn __statement(&self, client: &mut Client) -> Result<Statement, Error> {
client.prepare(self)
}
}
impl sealed::Sealed for Statement {}
impl ToStatement for Statement {
fn __statement(&self, _: &mut Client) -> Result<Statement, Error> {
Ok(self.clone())
}
}