meta_language/
link_flags.rs1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
3pub struct LinkFlags {
4 bits: u8,
5}
6
7impl LinkFlags {
8 const IS_ERROR: u8 = 0b0001;
9 const HAS_ERROR: u8 = 0b0010;
10 const IS_MISSING: u8 = 0b0100;
11 const IS_EXTRA: u8 = 0b1000;
12
13 #[must_use]
15 pub const fn clean() -> Self {
16 Self { bits: 0 }
17 }
18
19 #[must_use]
22 pub const fn error() -> Self {
23 Self {
24 bits: Self::IS_ERROR | Self::HAS_ERROR,
25 }
26 }
27
28 #[must_use]
30 pub const fn containing_error() -> Self {
31 Self {
32 bits: Self::HAS_ERROR,
33 }
34 }
35
36 #[must_use]
38 pub const fn missing() -> Self {
39 Self {
40 bits: Self::IS_MISSING | Self::HAS_ERROR,
41 }
42 }
43
44 #[must_use]
46 pub const fn extra() -> Self {
47 Self {
48 bits: Self::IS_EXTRA,
49 }
50 }
51
52 #[must_use]
54 pub const fn with_error(mut self) -> Self {
55 self.bits |= Self::IS_ERROR | Self::HAS_ERROR;
56 self
57 }
58
59 #[must_use]
61 pub const fn with_containing_error(mut self) -> Self {
62 self.bits |= Self::HAS_ERROR;
63 self
64 }
65
66 #[must_use]
68 pub const fn with_missing(mut self) -> Self {
69 self.bits |= Self::IS_MISSING | Self::HAS_ERROR;
70 self
71 }
72
73 #[must_use]
75 pub const fn with_extra(mut self) -> Self {
76 self.bits |= Self::IS_EXTRA;
77 self
78 }
79
80 #[must_use]
82 pub const fn is_error(self) -> bool {
83 self.bits & Self::IS_ERROR != 0
84 }
85
86 #[must_use]
89 pub const fn has_error(self) -> bool {
90 self.bits & Self::HAS_ERROR != 0
91 }
92
93 #[must_use]
95 pub const fn is_missing(self) -> bool {
96 self.bits & Self::IS_MISSING != 0
97 }
98
99 #[must_use]
101 pub const fn is_extra(self) -> bool {
102 self.bits & Self::IS_EXTRA != 0
103 }
104}