1pub enum Constant {
21 Bool(bool),
23 U32(u32),
25 U64(u64),
27 U128(u128),
29}
30
31impl Constant {
32 pub(super) fn required_bits(&self) -> u32 {
34 match *self {
35 Constant::Bool(value) => 32 - (value as u32).leading_zeros(),
36 Constant::U32(value) => 32 - value.leading_zeros(),
37 Constant::U64(value) => 64 - value.leading_zeros(),
38 Constant::U128(value) => 128 - value.leading_zeros(),
39 }
40 }
41
42 pub(crate) fn numeric_value(&self) -> u128 {
43 match *self {
44 Constant::Bool(value) => value.into(),
45 Constant::U32(value) => value.into(),
46 Constant::U64(value) => value.into(),
47 Constant::U128(value) => value,
48 }
49 }
50}
51
52impl From<bool> for Constant {
53 fn from(value: bool) -> Self {
54 Constant::Bool(value)
55 }
56}
57
58impl From<u8> for Constant {
59 fn from(value: u8) -> Self {
60 Constant::U32(value as _)
61 }
62}
63
64impl From<u16> for Constant {
65 fn from(value: u16) -> Self {
66 Constant::U32(value as _)
67 }
68}
69
70impl From<u32> for Constant {
71 fn from(value: u32) -> Self {
72 Constant::U32(value)
73 }
74}
75
76impl From<u64> for Constant {
77 fn from(value: u64) -> Self {
78 Constant::U64(value)
79 }
80}
81
82impl From<u128> for Constant {
83 fn from(value: u128) -> Self {
84 Constant::U128(value)
85 }
86}