Skip to main content

compose_lens/model/
blkio.rs

1use super::{FieldReference, Located};
2use crate::source::SourceSpan;
3
4/// Authored service block-I/O configuration without controller or runtime interpretation.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct BlkioConfig {
7    span: SourceSpan,
8    weight: Option<Located<BlkioScalar>>,
9    device_read_bps: Vec<BlkioDeviceRate>,
10    device_read_iops: Vec<BlkioDeviceRate>,
11    device_write_bps: Vec<BlkioDeviceRate>,
12    device_write_iops: Vec<BlkioDeviceRate>,
13    weight_device: Vec<BlkioWeightDevice>,
14    extension_fields: Vec<FieldReference>,
15    unknown_fields: Vec<FieldReference>,
16}
17
18impl BlkioConfig {
19    pub(super) fn new(span: SourceSpan) -> Self {
20        Self {
21            span,
22            weight: None,
23            device_read_bps: Vec::new(),
24            device_read_iops: Vec::new(),
25            device_write_bps: Vec::new(),
26            device_write_iops: Vec::new(),
27            weight_device: Vec::new(),
28            extension_fields: Vec::new(),
29            unknown_fields: Vec::new(),
30        }
31    }
32
33    pub(super) fn set_weight(&mut self, value: Located<BlkioScalar>) {
34        self.weight = Some(value);
35    }
36
37    pub(super) fn device_rates_mut(&mut self, name: &str) -> Option<&mut Vec<BlkioDeviceRate>> {
38        match name {
39            "device_read_bps" => Some(&mut self.device_read_bps),
40            "device_read_iops" => Some(&mut self.device_read_iops),
41            "device_write_bps" => Some(&mut self.device_write_bps),
42            "device_write_iops" => Some(&mut self.device_write_iops),
43            _ => None,
44        }
45    }
46
47    pub(super) fn weight_devices_mut(&mut self) -> &mut Vec<BlkioWeightDevice> {
48        &mut self.weight_device
49    }
50
51    pub(super) fn push_extension(&mut self, value: FieldReference) {
52        self.extension_fields.push(value);
53    }
54
55    pub(super) fn push_unknown(&mut self, value: FieldReference) {
56        self.unknown_fields.push(value);
57    }
58
59    /// Returns the complete mapping span.
60    #[must_use]
61    pub const fn span(&self) -> SourceSpan {
62        self.span
63    }
64
65    /// Returns the optional raw overall weight.
66    #[must_use]
67    pub const fn weight(&self) -> Option<&Located<BlkioScalar>> {
68        self.weight.as_ref()
69    }
70
71    /// Returns ordered read-byte-rate items.
72    #[must_use]
73    pub fn device_read_bps(&self) -> &[BlkioDeviceRate] {
74        &self.device_read_bps
75    }
76
77    /// Returns ordered read-I/O-rate items.
78    #[must_use]
79    pub fn device_read_iops(&self) -> &[BlkioDeviceRate] {
80        &self.device_read_iops
81    }
82
83    /// Returns ordered write-byte-rate items.
84    #[must_use]
85    pub fn device_write_bps(&self) -> &[BlkioDeviceRate] {
86        &self.device_write_bps
87    }
88
89    /// Returns ordered write-I/O-rate items.
90    #[must_use]
91    pub fn device_write_iops(&self) -> &[BlkioDeviceRate] {
92        &self.device_write_iops
93    }
94
95    /// Returns ordered device-weight items.
96    #[must_use]
97    pub fn weight_device(&self) -> &[BlkioWeightDevice] {
98        &self.weight_device
99    }
100
101    /// Returns retained extensions.
102    #[must_use]
103    pub fn extension_fields(&self) -> &[FieldReference] {
104        &self.extension_fields
105    }
106
107    /// Returns retained unknown or malformed members.
108    #[must_use]
109    pub fn unknown_fields(&self) -> &[FieldReference] {
110        &self.unknown_fields
111    }
112}
113
114/// Exact YAML integer-or-string spelling for a block-I/O weight or rate.
115#[derive(Debug, Clone, PartialEq, Eq)]
116#[non_exhaustive]
117pub enum BlkioScalar {
118    /// An exact YAML integer scalar spelling.
119    YamlInteger(String),
120    /// An exact YAML string scalar spelling.
121    String(String),
122}
123
124/// One ordered block-I/O device rate item.
125#[derive(Debug, Clone, PartialEq, Eq)]
126pub struct BlkioDeviceRate {
127    span: SourceSpan,
128    form: BlkioDeviceRateForm,
129    path: Option<Located<String>>,
130    rate: Option<Located<BlkioScalar>>,
131    extension_fields: Vec<FieldReference>,
132    unknown_fields: Vec<FieldReference>,
133}
134
135impl BlkioDeviceRate {
136    pub(super) fn new(span: SourceSpan) -> Self {
137        Self {
138            span,
139            form: BlkioDeviceRateForm::Mapping,
140            path: None,
141            rate: None,
142            extension_fields: Vec::new(),
143            unknown_fields: Vec::new(),
144        }
145    }
146
147    pub(super) fn unmodeled(span: SourceSpan) -> Self {
148        Self {
149            span,
150            form: BlkioDeviceRateForm::Unmodeled,
151            path: None,
152            rate: None,
153            extension_fields: Vec::new(),
154            unknown_fields: Vec::new(),
155        }
156    }
157
158    pub(super) fn set_path(&mut self, value: Located<String>) {
159        self.path = Some(value);
160    }
161
162    pub(super) fn set_rate(&mut self, value: Located<BlkioScalar>) {
163        self.rate = Some(value);
164    }
165
166    pub(super) fn push_extension(&mut self, value: FieldReference) {
167        self.extension_fields.push(value);
168    }
169
170    pub(super) fn push_unknown(&mut self, value: FieldReference) {
171        self.unknown_fields.push(value);
172    }
173
174    /// Returns the complete item span.
175    #[must_use]
176    pub const fn span(&self) -> SourceSpan {
177        self.span
178    }
179
180    /// Returns whether this entry was a mapping or retained unmodeled sequence item.
181    #[must_use]
182    pub const fn form(&self) -> BlkioDeviceRateForm {
183        self.form
184    }
185
186    /// Returns the raw device path when its YAML-string form was valid.
187    #[must_use]
188    pub const fn path(&self) -> Option<&Located<String>> {
189        self.path.as_ref()
190    }
191
192    /// Returns the raw integer-or-string rate when its scalar form was valid.
193    #[must_use]
194    pub const fn rate(&self) -> Option<&Located<BlkioScalar>> {
195        self.rate.as_ref()
196    }
197
198    /// Returns retained extensions on this entry.
199    #[must_use]
200    pub fn extension_fields(&self) -> &[FieldReference] {
201        &self.extension_fields
202    }
203
204    /// Returns retained unknown or malformed members on this entry.
205    #[must_use]
206    pub fn unknown_fields(&self) -> &[FieldReference] {
207        &self.unknown_fields
208    }
209}
210
211/// Authored block-I/O device-rate entry shape retained without coercion.
212#[derive(Debug, Clone, Copy, PartialEq, Eq)]
213#[non_exhaustive]
214pub enum BlkioDeviceRateForm {
215    /// A mapping-form entry.
216    Mapping,
217    /// A non-mapping sequence entry retained as evidence.
218    Unmodeled,
219}
220
221/// One ordered block-I/O device weight item.
222#[derive(Debug, Clone, PartialEq, Eq)]
223pub struct BlkioWeightDevice {
224    span: SourceSpan,
225    form: BlkioWeightDeviceForm,
226    path: Option<Located<String>>,
227    weight: Option<Located<BlkioScalar>>,
228    extension_fields: Vec<FieldReference>,
229    unknown_fields: Vec<FieldReference>,
230}
231
232impl BlkioWeightDevice {
233    pub(super) fn new(span: SourceSpan) -> Self {
234        Self {
235            span,
236            form: BlkioWeightDeviceForm::Mapping,
237            path: None,
238            weight: None,
239            extension_fields: Vec::new(),
240            unknown_fields: Vec::new(),
241        }
242    }
243
244    pub(super) fn unmodeled(span: SourceSpan) -> Self {
245        Self {
246            span,
247            form: BlkioWeightDeviceForm::Unmodeled,
248            path: None,
249            weight: None,
250            extension_fields: Vec::new(),
251            unknown_fields: Vec::new(),
252        }
253    }
254
255    pub(super) fn set_path(&mut self, value: Located<String>) {
256        self.path = Some(value);
257    }
258
259    pub(super) fn set_weight(&mut self, value: Located<BlkioScalar>) {
260        self.weight = Some(value);
261    }
262
263    pub(super) fn push_extension(&mut self, value: FieldReference) {
264        self.extension_fields.push(value);
265    }
266
267    pub(super) fn push_unknown(&mut self, value: FieldReference) {
268        self.unknown_fields.push(value);
269    }
270
271    /// Returns the complete item span.
272    #[must_use]
273    pub const fn span(&self) -> SourceSpan {
274        self.span
275    }
276
277    /// Returns whether this entry was a mapping or retained unmodeled sequence item.
278    #[must_use]
279    pub const fn form(&self) -> BlkioWeightDeviceForm {
280        self.form
281    }
282
283    /// Returns the raw device path when its YAML-string form was valid.
284    #[must_use]
285    pub const fn path(&self) -> Option<&Located<String>> {
286        self.path.as_ref()
287    }
288
289    /// Returns the raw integer-or-string weight when its scalar form was valid.
290    #[must_use]
291    pub const fn weight(&self) -> Option<&Located<BlkioScalar>> {
292        self.weight.as_ref()
293    }
294
295    /// Returns retained extensions on this entry.
296    #[must_use]
297    pub fn extension_fields(&self) -> &[FieldReference] {
298        &self.extension_fields
299    }
300
301    /// Returns retained unknown or malformed members on this entry.
302    #[must_use]
303    pub fn unknown_fields(&self) -> &[FieldReference] {
304        &self.unknown_fields
305    }
306}
307
308/// Authored block-I/O device-weight entry shape retained without coercion.
309#[derive(Debug, Clone, Copy, PartialEq, Eq)]
310#[non_exhaustive]
311pub enum BlkioWeightDeviceForm {
312    /// A mapping-form entry.
313    Mapping,
314    /// A non-mapping sequence entry retained as evidence.
315    Unmodeled,
316}