Path

Struct Path 

Source
pub struct Path<'a> { /* private fields */ }
Expand description

设备树节点路径。

Implementations§

Source§

impl Path<'_>

Source

pub fn level(&self) -> usize

返回路径层数。定义根节点的子节点层数为 0。

Examples found in repository?
examples/qemu-virt.rs (line 25)
6fn main() {
7    let mut aligned = vec![0usize; DEVICE_TREE.len() / core::mem::size_of::<usize>()];
8    unsafe {
9        aligned
10            .as_mut_ptr()
11            .copy_from_nonoverlapping(DEVICE_TREE.as_ptr() as _, aligned.len());
12    }
13
14    let dtb = unsafe {
15        Dtb::from_raw_parts_filtered(aligned.as_ptr() as _, |e| {
16            matches!(
17                e,
18                HeaderError::Misaligned(4) | HeaderError::LastCompVersion(16)
19            )
20        })
21    }
22    .unwrap();
23    dtb.walk(|path, obj| match obj {
24        DtbObj::SubNode { name } => {
25            println!("{}{path}/{}", indent(path.level(), INDENT_WIDTH), unsafe {
26                core::str::from_utf8_unchecked(name)
27            });
28            WalkOperation::StepInto
29        }
30        DtbObj::Property(prop) => {
31            let indent = indent(path.level(), INDENT_WIDTH);
32            println!("{indent}{prop:?}");
33            WalkOperation::StepOver
34        }
35    });
36    println!("ok");
37}
Source

pub fn last(&self) -> &[u8]

返回路径最后一级的节点名。

Source

pub fn join(&self, buf: &mut [u8]) -> Result<usize, usize>

将路径字符串格式化到 buf 中。

如果返回 Ok(n),表示字符串长度为 nn 不大于 buf.len())。 如果返回 Err(n),表示缓冲区长度无法存放整个字符串,实现保证 n 等于 buf.len()

Trait Implementations§

Source§

impl Display for Path<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Path<'a>

§

impl<'a> RefUnwindSafe for Path<'a>

§

impl<'a> Send for Path<'a>

§

impl<'a> Sync for Path<'a>

§

impl<'a> Unpin for Path<'a>

§

impl<'a> UnwindSafe for Path<'a>

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, 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.