use crate::database::Database;
use crate::encode::Encode;
use crate::error::BoxDynError;
use crate::types::Type;
use std::fmt::{self, Write};
#[allow(clippy::len_without_is_empty)]
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) -> Result<(), BoxDynError>
where
T: 'q + Encode<'q, Self::Database> + Type<Self::Database>;
fn len(&self) -> usize;
fn format_placeholder<W: Write>(&self, writer: &mut W) -> fmt::Result {
writer.write_str("?")
}
}
pub trait IntoArguments<'q, DB: Database>: Sized + Send {
fn into_arguments(self) -> <DB as Database>::Arguments<'q>;
}
#[macro_export]
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: Database>(pub <DB as Database>::Arguments<'q>);
impl<'q, DB: Database> IntoArguments<'q, DB> for ImmutableArguments<'q, DB> {
fn into_arguments(self) -> <DB as Database>::Arguments<'q> {
self.0
}
}