1use crate::database::Database;
4use crate::encode::Encode;
5use crate::error::BoxDynError;
6use crate::types::Type;
7use std::fmt::{self, Write};
8
9#[allow(clippy::len_without_is_empty)]
12pub trait Arguments<'q>: Send + Sized + Default {
13 type Database: Database;
14
15 fn reserve(&mut self, additional: usize, size: usize);
18
19 fn add<T>(&mut self, value: T) -> Result<(), BoxDynError>
21 where
22 T: 'q + Encode<'q, Self::Database> + Type<Self::Database>;
23
24 fn len(&self) -> usize;
26
27 fn format_placeholder<W: Write>(&self, writer: &mut W) -> fmt::Result {
28 writer.write_str("?")
29 }
30}
31
32pub trait IntoArguments<'q, DB: Database>: Sized + Send {
33 fn into_arguments(self) -> <DB as Database>::Arguments<'q>;
34}
35
36#[macro_export]
38macro_rules! impl_into_arguments_for_arguments {
39 ($Arguments:path) => {
40 impl<'q>
41 $crate::arguments::IntoArguments<
42 'q,
43 <$Arguments as $crate::arguments::Arguments<'q>>::Database,
44 > for $Arguments
45 {
46 fn into_arguments(self) -> $Arguments {
47 self
48 }
49 }
50 };
51}
52
53pub struct ImmutableArguments<'q, DB: Database>(pub <DB as Database>::Arguments<'q>);
55
56impl<'q, DB: Database> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> {
57 fn into_arguments(self) -> <DB as Database>::Arguments<'q> {
58 self.0
59 }
60}
61
62