teo_parser/value/
option_variant.rs1use std::ops::{BitAnd, BitOr, BitXor, Not};
2use bigdecimal::Zero;
3use serde::Serialize;
4use teo_result::Result;
5
6#[derive(Debug, Clone, PartialEq, Serialize)]
7pub struct OptionVariant {
8 pub value: i32,
9 pub display: String,
10}
11
12impl OptionVariant {
13
14 pub fn into_i32(self) -> i32 {
15 self.value
16 }
17
18 pub fn normal_not(&self) -> bool {
19 self.value.is_zero()
20 }
21}
22
23impl BitAnd for &OptionVariant {
24
25 type Output = Result<OptionVariant>;
26
27 fn bitand(self, rhs: Self) -> Self::Output {
28 Ok(OptionVariant {
29 value: self.value & rhs.value,
30 display: format!("({} & {})", self.display, rhs.display),
31 })
32 }
33}
34
35impl BitOr for &OptionVariant {
36
37 type Output = Result<OptionVariant>;
38
39 fn bitor(self, rhs: Self) -> Self::Output {
40 Ok(OptionVariant {
41 value: self.value | rhs.value,
42 display: format!("({} | {})", self.display, rhs.display),
43 })
44 }
45}
46
47impl BitXor for &OptionVariant {
48
49 type Output = Result<OptionVariant>;
50
51 fn bitxor(self, rhs: Self) -> Self::Output {
52 Ok(OptionVariant {
53 value: self.value ^ rhs.value,
54 display: format!("({} ^ {})", self.display, rhs.display),
55 })
56 }
57}
58
59impl Not for &OptionVariant {
60
61 type Output = OptionVariant;
62
63 fn not(self) -> Self::Output {
64 OptionVariant {
65 value: self.value.not(),
66 display: format!("~{}", self.display),
67 }
68 }
69}