pub struct Property {
pub name: String,
pub value: Vec<u8>,
}
Expand description
A property that describes a characteristic of node.
§Examples
You can create an empty property with a name:
use devicetree_tool::Property;
let prop = Property::new_empty("prop");
assert_eq!(prop.value, vec![]);
Or create a property with value in the type of u32
, u64
, str
or others.
use devicetree_tool::Property;
let prop = Property::new_u32("prop", 42);
assert_eq!(format!("{}", prop), "prop = <0x0 0x0 0x0 0x2a>;\n");
Fields§
§name: String
§value: Vec<u8>
Implementations§
Source§impl Property
impl Property
Sourcepub fn new_empty(name: &str) -> Self
pub fn new_empty(name: &str) -> Self
Create a Property
with a name, but without any value.
§Example
use devicetree_tool::Property;
let prop = Property::new_empty("prop");
assert_eq!(prop.value, vec![]);
assert_eq!(format!("{}", prop), "prop;\n");
Sourcepub fn new_u32(name: &str, value: u32) -> Self
pub fn new_u32(name: &str, value: u32) -> Self
Create a named Property
with the value of type u32
.
§Example
use devicetree_tool::Property;
let prop = Property::new_u32("prop", 42);
assert_eq!(prop.value, vec![0u8, 0u8, 0u8, 42u8]);
assert_eq!(format!("{}", prop), "prop = <0x0 0x0 0x0 0x2a>;\n");
Sourcepub fn new_u64(name: &str, value: u64) -> Self
pub fn new_u64(name: &str, value: u64) -> Self
Create a named Property
with the value of type u64
.
§Example
use devicetree_tool::Property;
let prop = Property::new_u64("prop", 42);
assert_eq!(prop.value, vec![0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 42u8]);
assert_eq!(format!("{}", prop), "prop = <0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x2a>;\n");
Sourcepub fn new_str(name: &str, value: &str) -> Self
pub fn new_str(name: &str, value: &str) -> Self
Create a named Property
with the value of string.
§Example
use devicetree_tool::Property;
let prop = Property::new_str("prop", "hello");
assert_eq!(prop.value, vec!['h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8, 0u8]);
assert_eq!(format!("{}", prop), "prop = <0x68 0x65 0x6c 0x6c 0x6f 0x0>;\n");
Sourcepub fn new_strs(name: &str, value: Vec<&str>) -> Self
pub fn new_strs(name: &str, value: Vec<&str>) -> Self
Create a named Property
with the value of a string list.
§Example
use devicetree_tool::Property;
let prop = Property::new_strs("prop", vec!["hello", "abc"]);
assert_eq!(prop.value, vec!['h' as u8, 'e' as u8, 'l' as u8, 'l' as u8, 'o' as u8, 0u8, 'a' as u8, 'b' as u8, 'c' as u8, 0u8]);
assert_eq!(format!("{}", prop), "prop = <0x68 0x65 0x6c 0x6c 0x6f 0x0 0x61 0x62 0x63 0x0>;\n");
Sourcepub fn new_u8s(name: &str, value: Vec<u8>) -> Self
pub fn new_u8s(name: &str, value: Vec<u8>) -> Self
Create a named Property
with the value of a u8
array.
§Example
use devicetree_tool::Property;
let prop = Property::new_u8s("prop", vec![1u8, 2u8, 3u8, 4u8]);
assert_eq!(prop.value, vec![1u8, 2u8, 3u8, 4u8]);
assert_eq!(format!("{}", prop), "prop = <0x1 0x2 0x3 0x4>;\n");
Sourcepub fn new_u32s(name: &str, value: Vec<u32>) -> Self
pub fn new_u32s(name: &str, value: Vec<u32>) -> Self
Create a named Property
with the value of a u32
array.
§Example
use devicetree_tool::Property;
let prop = Property::new_u32s("prop", vec![1u32, 2u32]);
assert_eq!(prop.value, vec![0u8, 0u8, 0u8, 1u8, 0u8, 0u8, 0u8, 2u8]);
assert_eq!(format!("{}", prop), "prop = <0x0 0x0 0x0 0x1 0x0 0x0 0x0 0x2>;\n");
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Property
impl RefUnwindSafe for Property
impl Send for Property
impl Sync for Property
impl Unpin for Property
impl UnwindSafe for Property
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more