bnr_xfs/config/
version.rs1use std::fmt;
2
3use crate::{create_xfs_i4, impl_xfs_struct};
4
5create_xfs_i4!(
6 Major,
7 "major",
8 "Represents the major component of the [Version]"
9);
10create_xfs_i4!(
11 Minor,
12 "minor",
13 "Represents the minor component of the [Version]"
14);
15
16#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub struct Version {
19 major: Major,
20 minor: Minor,
21}
22
23impl Version {
24 pub const fn new() -> Self {
26 Self {
27 major: Major::new(),
28 minor: Minor::new(),
29 }
30 }
31
32 pub const fn major(&self) -> Major {
34 self.major
35 }
36
37 pub fn set_major(&mut self, val: Major) {
39 self.major = val;
40 }
41
42 pub fn with_major(mut self, val: Major) -> Self {
44 self.set_major(val);
45 self
46 }
47
48 pub const fn minor(&self) -> Minor {
50 self.minor
51 }
52
53 pub fn set_minor(&mut self, val: Minor) {
55 self.minor = val;
56 }
57
58 pub fn with_minor(mut self, val: Minor) -> Self {
60 self.set_minor(val);
61 self
62 }
63}
64
65impl Default for Version {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71impl fmt::Display for Version {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 write!(f, "{{")?;
74 write!(f, r#""major":{},"#, self.major)?;
75 write!(f, r#""minor":{}"#, self.minor)?;
76 write!(f, "}}")
77 }
78}
79
80impl_xfs_struct!(Version, "version", [major: Major, minor: Minor]);
81
82create_xfs_i4!(
83 ModuleType,
84 "moduleType",
85 "Represents the module type of the [VersionRequirement]"
86);
87create_xfs_i4!(
88 ComponentType,
89 "componentType",
90 "Represents the component type of the [VersionRequirement]"
91);
92
93#[derive(Clone, Copy, Debug, Eq, PartialEq)]
95pub struct VersionRequirement {
96 module_type: ModuleType,
97 component_type: ComponentType,
98 version: Version,
99}
100
101impl VersionRequirement {
102 pub const fn new() -> Self {
104 Self {
105 module_type: ModuleType::new(),
106 component_type: ComponentType::new(),
107 version: Version::new(),
108 }
109 }
110
111 pub const fn module_type(&self) -> ModuleType {
113 self.module_type
114 }
115
116 pub fn set_module_type(&mut self, val: ModuleType) {
118 self.module_type = val;
119 }
120
121 pub fn with_module_type(mut self, val: ModuleType) -> Self {
123 self.set_module_type(val);
124 self
125 }
126
127 pub const fn component_type(&self) -> ComponentType {
129 self.component_type
130 }
131
132 pub fn set_component_type(&mut self, val: ComponentType) {
134 self.component_type = val;
135 }
136
137 pub fn with_component_type(mut self, val: ComponentType) -> Self {
139 self.set_component_type(val);
140 self
141 }
142
143 pub const fn version(&self) -> Version {
145 self.version
146 }
147
148 pub fn set_version(&mut self, val: Version) {
150 self.version = val;
151 }
152
153 pub fn with_version(mut self, val: Version) -> Self {
155 self.set_version(val);
156 self
157 }
158}
159
160impl Default for VersionRequirement {
161 fn default() -> Self {
162 Self::new()
163 }
164}
165
166impl fmt::Display for VersionRequirement {
167 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168 write!(f, "{{")?;
169 write!(f, r#""module_type":{},"#, self.module_type)?;
170 write!(f, r#""component_type":{},"#, self.component_type)?;
171 write!(f, r#""version":{}"#, self.version)?;
172 write!(f, "}}")
173 }
174}
175
176impl_xfs_struct!(
177 VersionRequirement,
178 "versionRequirement",
179 [
180 module_type: ModuleType,
181 component_type: ComponentType,
182 version: Version
183 ]
184);