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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::database::{Database, HasArguments};
use crate::encode::Encode;
use crate::types::Type;
use std::fmt::{self, Write};
pub trait Arguments<'q>: Send + Sized + Default {
type Database: Database;
fn reserve(&mut self, additional: usize, size: usize);
fn add<T>(&mut self, value: T)
where
T: 'q + Send + Encode<'q, Self::Database> + Type<Self::Database>;
fn format_placeholder<W: Write>(&self, writer: &mut W) -> fmt::Result {
writer.write_str("?")
}
}
pub trait IntoArguments<'q, DB: HasArguments<'q>>: Sized + Send {
fn into_arguments(self) -> <DB as HasArguments<'q>>::Arguments;
}
#[allow(unused_macros)]
macro_rules! impl_into_arguments_for_arguments {
($Arguments:path) => {
impl<'q>
crate::arguments::IntoArguments<
'q,
<$Arguments as crate::arguments::Arguments<'q>>::Database,
> for $Arguments
{
fn into_arguments(self) -> $Arguments {
self
}
}
};
}
pub struct ImmutableArguments<'q, DB: HasArguments<'q>>(pub <DB as HasArguments<'q>>::Arguments);
impl<'q, DB: HasArguments<'q>> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> {
fn into_arguments(self) -> <DB as HasArguments<'q>>::Arguments {
self.0
}
}