use alloc::string::{String, ToString};
use alloc::vec::Vec;
use core::str;
use crate::Property;
use crate::error::FdtParseError;
use crate::fdt::FdtProperty;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DeviceTreeProperty {
name: String,
value: Vec<u8>,
}
impl<'a> Property<'a> for &'a DeviceTreeProperty {
fn name(&self) -> &'a str {
&self.name
}
fn value(&self) -> &'a [u8] {
&self.value
}
}
impl DeviceTreeProperty {
#[must_use]
pub fn new(name: impl Into<String>, value: impl Into<Vec<u8>>) -> Self {
Self {
name: name.into(),
value: value.into(),
}
}
pub fn set_value(&mut self, value: impl Into<Vec<u8>>) {
self.value = value.into();
}
}
impl<'a> TryFrom<FdtProperty<'a>> for DeviceTreeProperty {
type Error = FdtParseError;
fn try_from(prop: FdtProperty<'a>) -> Result<Self, Self::Error> {
let name = prop.name().to_string();
let value = prop.value().to_vec();
Ok(DeviceTreeProperty { name, value })
}
}