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: Send + Sized + Default {
13 type Database: Database;
14
15 fn reserve(&mut self, additional: usize, size: usize);
18
19 fn add<'t, T>(&mut self, value: T) -> Result<(), BoxDynError>
21 where
22 T: Encode<'t, 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<DB: Database>: Sized + Send {
33 fn into_arguments(self) -> <DB as Database>::Arguments;
34}
35
36#[macro_export]
38macro_rules! impl_into_arguments_for_arguments {
39 ($Arguments:path) => {
40 impl
41 $crate::arguments::IntoArguments<<$Arguments as $crate::arguments::Arguments>::Database>
42 for $Arguments
43 {
44 fn into_arguments(self) -> $Arguments {
45 self
46 }
47 }
48 };
49}
50
51pub struct ImmutableArguments<DB: Database>(pub <DB as Database>::Arguments);
53
54impl<DB: Database> IntoArguments<DB> for ImmutableArguments<DB> {
55 fn into_arguments(self) -> <DB as Database>::Arguments {
56 self.0
57 }
58}