use super::Load;
use crate::stmt::{self, List};
pub trait Field: Load {
type Path<Origin>;
type ListPath<Origin>;
type Update<'a>;
const NULLABLE: bool = false;
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin>
where
Self: Sized;
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin>
where
Self: Sized;
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a>;
fn field_ty(
storage_ty: Option<toasty_core::schema::db::Type>,
) -> toasty_core::schema::app::FieldTy {
toasty_core::schema::app::FieldTy::Primitive(toasty_core::schema::app::FieldPrimitive {
ty: Self::ty(),
storage_ty,
serialize: None,
})
}
}
macro_rules! impl_field_primitive {
($ty:ty) => {
impl Field for $ty {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(
path: stmt::Path<Origin, List<Self>>,
) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
};
}
impl_field_primitive!(String);
impl_field_primitive!(uuid::Uuid);
impl_field_primitive!(bool);
impl_field_primitive!(isize);
impl_field_primitive!(usize);
impl Field for Vec<u8> {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
fn field_ty(
storage_ty: Option<toasty_core::schema::db::Type>,
) -> toasty_core::schema::app::FieldTy {
toasty_core::schema::app::FieldTy::Primitive(toasty_core::schema::app::FieldPrimitive {
ty: toasty_core::stmt::Type::Bytes,
storage_ty,
serialize: None,
})
}
}
impl<T: Field> Field for Option<T> {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
const NULLABLE: bool = true;
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
impl<T> Field for std::borrow::Cow<'_, T>
where
T: ToOwned + ?Sized,
T::Owned: Field<Output = T::Owned>,
{
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
impl<T: Field<Output = T>> Field for std::sync::Arc<T> {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
impl<T: Field<Output = T>> Field for std::rc::Rc<T> {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
impl<T: Field<Output = T>> Field for Box<T> {
type Path<Origin> = stmt::Path<Origin, Self>;
type ListPath<Origin> = stmt::Path<Origin, List<Self>>;
type Update<'a> = ();
fn new_path<Origin>(path: stmt::Path<Origin, Self>) -> Self::Path<Origin> {
path
}
fn new_list_path<Origin>(path: stmt::Path<Origin, List<Self>>) -> Self::ListPath<Origin> {
path
}
fn new_update<'a>(
_assignments: &'a mut toasty_core::stmt::Assignments,
_projection: toasty_core::stmt::Projection,
) -> Self::Update<'a> {
}
}
#[cfg(feature = "rust_decimal")]
impl_field_primitive!(rust_decimal::Decimal);
#[cfg(feature = "bigdecimal")]
impl_field_primitive!(bigdecimal::BigDecimal);