diff --git a/acpi_tables/src/aml.rs b/acpi_tables/src/aml.rs index 1c04f7734..f6aaf0946 100644 --- a/acpi_tables/src/aml.rs +++ b/acpi_tables/src/aml.rs @@ -285,6 +285,30 @@ impl Aml for Usize { } } +fn create_aml_string(v: &str) -> Vec { + let mut data = Vec::new(); + data.push(0x0D); /* String Op */ + data.extend_from_slice(v.as_bytes()); + data.push(0x0); /* NullChar */ + data +} + +pub type AmlStr = &'static str; + +impl Aml for AmlStr { + fn to_aml_bytes(&self) -> Vec { + create_aml_string(self) + } +} + +pub type AmlString = String; + +impl Aml for AmlString { + fn to_aml_bytes(&self) -> Vec { + create_aml_string(self) + } +} + pub struct ResourceTemplate<'a> { children: Vec<&'a dyn Aml>, } @@ -991,4 +1015,16 @@ mod tests { ] ); } + + #[test] + fn test_string() { + assert_eq!( + (&"ACPI" as &dyn Aml).to_aml_bytes(), + [0x0d, b'A', b'C', b'P', b'I', 0] + ); + assert_eq!( + "ACPI".to_owned().to_aml_bytes(), + [0x0d, b'A', b'C', b'P', b'I', 0] + ); + } }