pub struct Node {
pub name: String,
pub description: String,
pub kind: NodeType,
/* private fields */
}Expand description
Node of the Crash Log register tree
Fields§
§name: StringName of the node
description: StringDescription of the node
kind: NodeTypeType of the node
Implementations§
Source§impl Node
impl Node
Sourcepub fn root() -> Node
pub fn root() -> Node
Returns a new root node.
§Examples
use intel_crashlog::prelude::*;
let root = Node::root();
assert_eq!(root.kind, NodeType::Root);Sourcepub fn section(name: &str) -> Node
pub fn section(name: &str) -> Node
Returns a new section node.
§Examples
use intel_crashlog::prelude::*;
let node = Node::section("foo");
assert_eq!(node.kind, NodeType::Section);
assert_eq!(node.name, "foo");Sourcepub fn record(name: &str) -> Node
pub fn record(name: &str) -> Node
Returns a new record node.
§Examples
use intel_crashlog::prelude::*;
let node = Node::record("foo");
assert_eq!(node.kind, NodeType::Record);
assert_eq!(node.name, "foo");Sourcepub fn field(name: &str, value: u64) -> Node
pub fn field(name: &str, value: u64) -> Node
Returns a new field node.
§Examples
use intel_crashlog::prelude::*;
let node = Node::field("foo", 42);
assert_eq!(node.kind, NodeType::Field { value: 42 });
assert_eq!(node.name, "foo");Sourcepub fn get_mut(&mut self, name: &str) -> Option<&mut Node>
pub fn get_mut(&mut self, name: &str) -> Option<&mut Node>
Returns a mutable reference to a child of the node. If the child does not exist, None
is returned.
§Examples
use intel_crashlog::prelude::*;
let mut node = Node::section("foo");
node.add(Node::section("bar"));
if let Some(child) = node.get_mut("bar") {
// Change the node type
child.kind = NodeType::Field { value: 42 };
}
assert_eq!(node.get("bar"), Some(&Node::field("bar", 42)));Sourcepub fn get_by_path(&self, path: &str) -> Option<&Node>
pub fn get_by_path(&self, path: &str) -> Option<&Node>
Returns a reference to the node in the tree located at the specified path. The path
consists in a &str representing the names of the parent nodes separated by . (For
example: foo.bar.baz).
§Examples
use intel_crashlog::prelude::*;
let mut foo = Node::section("foo");
foo.add(Node::section("bar"));
let mut root = Node::root();
root.add(foo);
assert_eq!(root.get_by_path("foo.bar"), Some(&Node::section("bar")));
assert_eq!(root.get_by_path("foo.baz"), None);Sourcepub fn value(&self) -> Option<u64>
pub fn value(&self) -> Option<u64>
Returns the value associated to the node if present.
§Examples
use intel_crashlog::prelude::*;
let field = Node::field("foo", 42);
assert_eq!(field.value(), Some(42));
let section = Node::section("bar");
assert_eq!(section.value(), None);Sourcepub fn get_value_by_path(&self, path: &str) -> Option<u64>
pub fn get_value_by_path(&self, path: &str) -> Option<u64>
Returns the value of the field stored at the given path.
§Examples
use intel_crashlog::prelude::*;
let mut foo = Node::section("foo");
foo.add(Node::field("bar", 42));
let mut root = Node::root();
root.add(foo);
assert_eq!(root.get_value_by_path("foo.bar"), Some(42));
assert_eq!(root.get_value_by_path("foo"), None);
assert_eq!(root.get_value_by_path("foo.baz"), None);pub fn merge(&mut self, other: Node)
pub fn add(&mut self, node: Node)
pub fn create_hierarchy(&mut self, path: &str) -> &mut Node
Sourcepub fn children(&self) -> NodeChildren<'_> ⓘ
pub fn children(&self) -> NodeChildren<'_> ⓘ
Returns an iterator over the node’s children. The children nodes are sorted alphabetically.
§Examples
use intel_crashlog::prelude::*;
let mut root = Node::root();
root.add(Node::section("foo"));
root.add(Node::section("bar"));
let mut children = root.children();
assert_eq!(children.next(), Some(&Node::section("bar")));
assert_eq!(children.next(), Some(&Node::section("foo")));
assert_eq!(children.next(), None);Trait Implementations§
Source§impl From<&RecordSize> for Node
impl From<&RecordSize> for Node
Source§fn from(size: &RecordSize) -> Self
fn from(size: &RecordSize) -> Self
Converts to this type from the input type.
impl Eq for Node
impl StructuralPartialEq for Node
Auto Trait Implementations§
impl Freeze for Node
impl RefUnwindSafe for Node
impl Send for Node
impl Sync for Node
impl Unpin for Node
impl UnsafeUnpin for Node
impl UnwindSafe for Node
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