polars_utils/
nulls.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
pub trait IsNull {
    const HAS_NULLS: bool;
    type Inner;

    fn is_null(&self) -> bool;

    fn unwrap_inner(self) -> Self::Inner;
}

impl<T> IsNull for Option<T> {
    const HAS_NULLS: bool = true;
    type Inner = T;

    #[inline(always)]
    fn is_null(&self) -> bool {
        self.is_none()
    }

    #[inline(always)]
    fn unwrap_inner(self) -> Self::Inner {
        Option::unwrap(self)
    }
}

macro_rules! impl_is_null (
    ($($ty:tt)*) => {
        impl IsNull for $($ty)* {
            const HAS_NULLS: bool = false;
            type Inner = $($ty)*;


            #[inline(always)]
            fn is_null(&self) -> bool {
                false
            }

            #[inline(always)]
            fn unwrap_inner(self) -> $($ty)* {
                self
            }
        }
    };
);

impl_is_null!(bool);
impl_is_null!(f32);
impl_is_null!(f64);
impl_is_null!(i8);
impl_is_null!(i16);
impl_is_null!(i32);
impl_is_null!(i64);
impl_is_null!(i128);
impl_is_null!(u8);
impl_is_null!(u16);
impl_is_null!(u32);
impl_is_null!(u64);
impl_is_null!(u128);

impl<'a> IsNull for &'a [u8] {
    const HAS_NULLS: bool = false;
    type Inner = &'a [u8];

    #[inline(always)]
    fn is_null(&self) -> bool {
        false
    }

    #[inline(always)]
    fn unwrap_inner(self) -> Self::Inner {
        self
    }
}

impl<'a, T: IsNull + ?Sized> IsNull for &'a T {
    const HAS_NULLS: bool = false;
    type Inner = &'a T;

    fn is_null(&self) -> bool {
        (*self).is_null()
    }

    fn unwrap_inner(self) -> Self::Inner {
        self
    }
}