libcre/
null.rs

1use std::ops::{Deref, DerefMut};
2
3pub trait Null {
4    fn null() -> Self;
5    fn is_null(&self) -> bool;
6}
7pub fn null<T: Null>() -> T {
8    T::null()
9}
10
11pub struct Val<T: Null> {
12    pub value: T
13}
14pub trait Valid: Sized + Null {
15    fn valid(self) -> Val<Self> {
16        debug_assert!(!self.is_null());
17        Val::<Self> {
18            value: self
19        }
20    }
21}
22impl<T: Null> Valid for T {
23}
24
25impl<T: Null> Deref for Val<T> {
26    type Target = T;
27
28    #[inline]
29    fn deref(&self) -> &Self::Target {
30        &self.value
31    }
32}
33impl<T: Null> DerefMut for Val<T> {
34    #[inline]
35    fn deref_mut(&mut self) -> &mut Self::Target {
36        &mut self.value
37    }
38}