Skip to main content

Node

Struct Node 

Source
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: String

Name of the node

§description: String

Description of the node

§kind: NodeType

Type of the node

Implementations§

Source§

impl Node

Source

pub fn root() -> Node

Returns a new root node.

§Examples
use intel_crashlog::prelude::*;

let root = Node::root();
assert_eq!(root.kind, NodeType::Root);
Source

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

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

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

pub fn get(&self, name: &str) -> Option<&Node>

Returns a 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"));
assert_eq!(node.get("bar"), Some(&Node::section("bar")));
assert_eq!(node.get("baz"), None);
Source

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

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

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

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

pub fn merge(&mut self, other: Node)

Source

pub fn add(&mut self, node: Node)

Source

pub fn create_hierarchy(&mut self, path: &str) -> &mut Node

Source

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 Debug for Node

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Node

Source§

fn default() -> Node

Returns the “default value” for a type. Read more
Source§

impl From<&Header> for Node

Source§

fn from(header: &Header) -> Self

Converts to this type from the input type.
Source§

impl From<&RecordSize> for Node

Source§

fn from(size: &RecordSize) -> Self

Converts to this type from the input type.
Source§

impl From<&Version> for Node

Source§

fn from(version: &Version) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Node

Source§

fn eq(&self, other: &Node) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Node

Available on crate feature serialize only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Node

Source§

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