pub struct Path<'a> { /* private fields */ }Expand description
设备树节点路径。
Implementations§
Source§impl Path<'_>
impl Path<'_>
Sourcepub fn level(&self) -> usize
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}Trait Implementations§
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> 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