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]
21 pub const fn error() -> Self {
22 Self {
23 bits: Self::IS_ERROR,
24 }
25 }
26
27 #[must_use]
29 pub const fn containing_error() -> Self {
30 Self {
31 bits: Self::HAS_ERROR,
32 }
33 }
34
35 #[must_use]
37 pub const fn missing() -> Self {
38 Self {
39 bits: Self::IS_MISSING,
40 }
41 }
42
43 #[must_use]
45 pub const fn extra() -> Self {
46 Self {
47 bits: Self::IS_EXTRA,
48 }
49 }
50
51 #[must_use]
53 pub const fn with_error(mut self) -> Self {
54 self.bits |= Self::IS_ERROR;
55 self
56 }
57
58 #[must_use]
60 pub const fn with_containing_error(mut self) -> Self {
61 self.bits |= Self::HAS_ERROR;
62 self
63 }
64
65 #[must_use]
67 pub const fn with_missing(mut self) -> Self {
68 self.bits |= Self::IS_MISSING;
69 self
70 }
71
72 #[must_use]
74 pub const fn with_extra(mut self) -> Self {
75 self.bits |= Self::IS_EXTRA;
76 self
77 }
78
79 #[must_use]
81 pub const fn is_error(self) -> bool {
82 self.bits & Self::IS_ERROR != 0
83 }
84
85 #[must_use]
87 pub const fn has_error(self) -> bool {
88 self.bits & Self::HAS_ERROR != 0
89 }
90
91 #[must_use]
93 pub const fn is_missing(self) -> bool {
94 self.bits & Self::IS_MISSING != 0
95 }
96
97 #[must_use]
99 pub const fn is_extra(self) -> bool {
100 self.bits & Self::IS_EXTRA != 0
101 }
102}