Skip to main content

rust_rel8/
is_nullable.rs

1//! Helper trait that is used to mark if a type could be `NULL` on the SQL side.
2
3/// Helper trait that is used to mark if a type could be `NULL` on the SQL side.
4pub trait IsNullable {
5    /// Is this type nullable
6    const IS_NULLABLE: bool;
7}
8
9macro_rules! impl_is_nullable_not {
10    ($($ty:ty,)* $(,)?) => {
11        $(
12            impl IsNullable for $ty {
13                const IS_NULLABLE: bool = false;
14            }
15         )*
16    };
17}
18
19impl_is_nullable_not!(
20    bool, char, f32, f64, i8, i16, i32, i64, u8, u16, u32, u64, String,
21);
22
23impl<T> IsNullable for Option<T> {
24    const IS_NULLABLE: bool = true;
25}
26
27impl<T: IsNullable> IsNullable for Vec<T> {
28    const IS_NULLABLE: bool = T::IS_NULLABLE;
29}