polars_utils/
nulls.rs
1pub trait IsNull {
2 const HAS_NULLS: bool;
3 type Inner;
4
5 fn is_null(&self) -> bool;
6
7 fn unwrap_inner(self) -> Self::Inner;
8}
9
10impl<T> IsNull for Option<T> {
11 const HAS_NULLS: bool = true;
12 type Inner = T;
13
14 #[inline(always)]
15 fn is_null(&self) -> bool {
16 self.is_none()
17 }
18
19 #[inline(always)]
20 fn unwrap_inner(self) -> Self::Inner {
21 Option::unwrap(self)
22 }
23}
24
25macro_rules! impl_is_null (
26 ($($ty:tt)*) => {
27 impl IsNull for $($ty)* {
28 const HAS_NULLS: bool = false;
29 type Inner = $($ty)*;
30
31
32 #[inline(always)]
33 fn is_null(&self) -> bool {
34 false
35 }
36
37 #[inline(always)]
38 fn unwrap_inner(self) -> $($ty)* {
39 self
40 }
41 }
42 };
43);
44
45impl_is_null!(bool);
46impl_is_null!(f32);
47impl_is_null!(f64);
48impl_is_null!(i8);
49impl_is_null!(i16);
50impl_is_null!(i32);
51impl_is_null!(i64);
52impl_is_null!(i128);
53impl_is_null!(u8);
54impl_is_null!(u16);
55impl_is_null!(u32);
56impl_is_null!(u64);
57impl_is_null!(u128);
58
59impl<'a> IsNull for &'a [u8] {
60 const HAS_NULLS: bool = false;
61 type Inner = &'a [u8];
62
63 #[inline(always)]
64 fn is_null(&self) -> bool {
65 false
66 }
67
68 #[inline(always)]
69 fn unwrap_inner(self) -> Self::Inner {
70 self
71 }
72}
73
74impl<'a, T: IsNull + ?Sized> IsNull for &'a T {
75 const HAS_NULLS: bool = false;
76 type Inner = &'a T;
77
78 fn is_null(&self) -> bool {
79 (*self).is_null()
80 }
81
82 fn unwrap_inner(self) -> Self::Inner {
83 self
84 }
85}