pub trait Nullable: PartialEq + Sized {
const NONE: Self;
fn is_none(&self) -> bool {
self == &Self::NONE
}
fn is_some(&self) -> bool {
!self.is_none()
}
}
macro_rules! nullable_integer {
( $type:tt ) => {
#[doc = concat!("Implements `Nullable` for the `", stringify!($type), "` type, reserving `0` as the `NONE` value.")]
impl Nullable for $type {
const NONE: Self = 0;
}
};
}
nullable_integer!(u8);
nullable_integer!(u16);
nullable_integer!(u32);
nullable_integer!(u64);
#[cfg(not(target_arch = "bpf"))]
nullable_integer!(u128);