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