use super::{FieldReference, Located};
use crate::source::SourceSpan;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlkioConfig {
span: SourceSpan,
weight: Option<Located<BlkioScalar>>,
device_read_bps: Vec<BlkioDeviceRate>,
device_read_iops: Vec<BlkioDeviceRate>,
device_write_bps: Vec<BlkioDeviceRate>,
device_write_iops: Vec<BlkioDeviceRate>,
weight_device: Vec<BlkioWeightDevice>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl BlkioConfig {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
weight: None,
device_read_bps: Vec::new(),
device_read_iops: Vec::new(),
device_write_bps: Vec::new(),
device_write_iops: Vec::new(),
weight_device: Vec::new(),
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_weight(&mut self, value: Located<BlkioScalar>) {
self.weight = Some(value);
}
pub(super) fn device_rates_mut(&mut self, name: &str) -> Option<&mut Vec<BlkioDeviceRate>> {
match name {
"device_read_bps" => Some(&mut self.device_read_bps),
"device_read_iops" => Some(&mut self.device_read_iops),
"device_write_bps" => Some(&mut self.device_write_bps),
"device_write_iops" => Some(&mut self.device_write_iops),
_ => None,
}
}
pub(super) fn weight_devices_mut(&mut self) -> &mut Vec<BlkioWeightDevice> {
&mut self.weight_device
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn weight(&self) -> Option<&Located<BlkioScalar>> {
self.weight.as_ref()
}
#[must_use]
pub fn device_read_bps(&self) -> &[BlkioDeviceRate] {
&self.device_read_bps
}
#[must_use]
pub fn device_read_iops(&self) -> &[BlkioDeviceRate] {
&self.device_read_iops
}
#[must_use]
pub fn device_write_bps(&self) -> &[BlkioDeviceRate] {
&self.device_write_bps
}
#[must_use]
pub fn device_write_iops(&self) -> &[BlkioDeviceRate] {
&self.device_write_iops
}
#[must_use]
pub fn weight_device(&self) -> &[BlkioWeightDevice] {
&self.weight_device
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlkioScalar {
YamlInteger(String),
String(String),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlkioDeviceRate {
span: SourceSpan,
form: BlkioDeviceRateForm,
path: Option<Located<String>>,
rate: Option<Located<BlkioScalar>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl BlkioDeviceRate {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
form: BlkioDeviceRateForm::Mapping,
path: None,
rate: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: BlkioDeviceRateForm::Unmodeled,
path: None,
rate: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_path(&mut self, value: Located<String>) {
self.path = Some(value);
}
pub(super) fn set_rate(&mut self, value: Located<BlkioScalar>) {
self.rate = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> BlkioDeviceRateForm {
self.form
}
#[must_use]
pub const fn path(&self) -> Option<&Located<String>> {
self.path.as_ref()
}
#[must_use]
pub const fn rate(&self) -> Option<&Located<BlkioScalar>> {
self.rate.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlkioDeviceRateForm {
Mapping,
Unmodeled,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlkioWeightDevice {
span: SourceSpan,
form: BlkioWeightDeviceForm,
path: Option<Located<String>>,
weight: Option<Located<BlkioScalar>>,
extension_fields: Vec<FieldReference>,
unknown_fields: Vec<FieldReference>,
}
impl BlkioWeightDevice {
pub(super) fn new(span: SourceSpan) -> Self {
Self {
span,
form: BlkioWeightDeviceForm::Mapping,
path: None,
weight: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn unmodeled(span: SourceSpan) -> Self {
Self {
span,
form: BlkioWeightDeviceForm::Unmodeled,
path: None,
weight: None,
extension_fields: Vec::new(),
unknown_fields: Vec::new(),
}
}
pub(super) fn set_path(&mut self, value: Located<String>) {
self.path = Some(value);
}
pub(super) fn set_weight(&mut self, value: Located<BlkioScalar>) {
self.weight = Some(value);
}
pub(super) fn push_extension(&mut self, value: FieldReference) {
self.extension_fields.push(value);
}
pub(super) fn push_unknown(&mut self, value: FieldReference) {
self.unknown_fields.push(value);
}
#[must_use]
pub const fn span(&self) -> SourceSpan {
self.span
}
#[must_use]
pub const fn form(&self) -> BlkioWeightDeviceForm {
self.form
}
#[must_use]
pub const fn path(&self) -> Option<&Located<String>> {
self.path.as_ref()
}
#[must_use]
pub const fn weight(&self) -> Option<&Located<BlkioScalar>> {
self.weight.as_ref()
}
#[must_use]
pub fn extension_fields(&self) -> &[FieldReference] {
&self.extension_fields
}
#[must_use]
pub fn unknown_fields(&self) -> &[FieldReference] {
&self.unknown_fields
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum BlkioWeightDeviceForm {
Mapping,
Unmodeled,
}