Struct Property

Source
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

Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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");
Source

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§

Source§

impl Display for Property

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Print a Property in the format of DTS

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.