Skip to content

Commit c167ed8

Browse files
m4txqwandor
andauthored
Add more crate-level docs (#9)
* Support writing FDT from the in-memory representation * use ALL_DT_FILES * Add more crate-level docs * address review comment * more zerocopy * address review comment * tiny fixes * address review comments * format --------- Co-authored-by: Andrew Walbran <[email protected]>
1 parent aaabd29 commit c167ed8

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,59 @@
1818
//! The library is written purely in Rust and is `#![no_std]` compatible. If
1919
//! you don't need the Device Tree manipulation functionality, the library is
2020
//! also no-`alloc`-compatible.
21+
//!
22+
//! ## Read-Only API
23+
//!
24+
//! The read-only API is centered around the [`Fdt`](fdt::Fdt) struct, which
25+
//! provides a safe, zero-copy view of an FDT blob. You can use this API
26+
//! to traverse the device tree, inspect nodes and properties, and read
27+
//! property values.
28+
//!
29+
//! Note that because the [`Fdt`](fdt::Fdt) struct is zero-copy, certain
30+
//! operations such as node or property lookups run in linear time. If you need
31+
//! to perform these operations often, and you can spare extra memory, it might
32+
//! be beneficial to convert from [`Fdt`](fdt::Fdt) to
33+
//! [`DeviceTree`](model::DeviceTree) first.
34+
//!
35+
//! ## Read-Write API
36+
//!
37+
//! The read-write API is centered around the [`DeviceTree`](model::DeviceTree)
38+
//! struct, which provides a mutable, in-memory representation of a device tree.
39+
//! You can use this API to create new device trees from scratch, modify
40+
//! existing ones, and serialize them back to an FDT blob.
41+
//!
42+
//! Internally it is built upon hash maps, meaning that most lookup and
43+
//! modification operations run in constant time.
44+
//!
45+
//! # Examples
46+
//!
47+
//! ```
48+
//! use dtoolkit::fdt::Fdt;
49+
//! use dtoolkit::model::{DeviceTree, DeviceTreeNode, DeviceTreeProperty};
50+
//!
51+
//! // Create a new device tree from scratch.
52+
//! let mut tree = DeviceTree::new();
53+
//!
54+
//! // Add a child node to the root.
55+
//! let child = DeviceTreeNode::builder("child")
56+
//! .property(DeviceTreeProperty::new("my-property", "hello\0"))
57+
//! .build();
58+
//! tree.root.add_child(child);
59+
//!
60+
//! // Serialize the device tree to a DTB.
61+
//! let dtb = tree.to_dtb();
62+
//!
63+
//! // Parse the DTB with the read-only API.
64+
//! let fdt = Fdt::new(&dtb).unwrap();
65+
//!
66+
//! // Find the child node and read its property.
67+
//! let child_node = fdt.find_node("/child").unwrap().unwrap();
68+
//! let prop = child_node.property("my-property").unwrap().unwrap();
69+
//! assert_eq!(prop.as_str().unwrap(), "hello");
70+
//!
71+
//! // Display the DTS
72+
//! println!("{}", fdt);
73+
//! ```
2174
2275
#![no_std]
2376
#![warn(missing_docs, rustdoc::missing_crate_level_docs)]

0 commit comments

Comments
 (0)