vortex_dtype/
nullability.rs1use std::fmt::{Display, Formatter};
2use std::ops::BitOr;
3
4#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
6pub enum Nullability {
7 #[default]
9 NonNullable,
10 Nullable,
12}
13
14impl Nullability {
15 pub fn verbose_display(&self) -> impl Display {
19 match self {
20 Nullability::NonNullable => "NonNullable",
21 Nullability::Nullable => "Nullable",
22 }
23 }
24}
25
26impl BitOr for Nullability {
27 type Output = Nullability;
28
29 fn bitor(self, rhs: Self) -> Self::Output {
30 match (self, rhs) {
31 (Self::NonNullable, Self::NonNullable) => Self::NonNullable,
32 _ => Self::Nullable,
33 }
34 }
35}
36
37impl From<bool> for Nullability {
38 fn from(value: bool) -> Self {
39 if value {
40 Self::Nullable
41 } else {
42 Self::NonNullable
43 }
44 }
45}
46
47impl From<Nullability> for bool {
48 fn from(value: Nullability) -> Self {
49 match value {
50 Nullability::NonNullable => false,
51 Nullability::Nullable => true,
52 }
53 }
54}
55
56impl Display for Nullability {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 match self {
59 Self::NonNullable => write!(f, ""),
60 Self::Nullable => write!(f, "?"),
61 }
62 }
63}