use std::fmt;
pub const CONTROL_BLOCK_PROPERTY: &str = "control-block";
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SidecarCommand {
pub binary: &'static str,
pub machine: &'static str,
pub cpu: &'static str,
pub properties: Vec<Property>,
pub icount_shift: u32,
pub aliases: Vec<Alias>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Property {
pub name: &'static str,
pub value: String,
}
impl Property {
pub fn new(name: &'static str, value: impl fmt::Display) -> Self {
Self {
name,
value: value.to_string(),
}
}
}
impl fmt::Display for Property {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(formatter, "{}={}", self.name, self.value)
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Alias {
pub region: &'static str,
pub at: u64,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_property_renders_as_the_machine_spells_it() {
assert_eq!(Property::new("num-irq", 91u16).to_string(), "num-irq=91");
assert_eq!(
Property::new("control-block", "cb").to_string(),
"control-block=cb"
);
}
}