Skip to main content

NodeInfo

Struct NodeInfo 

Source
pub struct NodeInfo {
    pub type_name: String,
    pub id: String,
    pub fields: Vec<Value>,
    pub depth: usize,
    pub parent_id: Option<String>,
    pub parent_type: Option<String>,
    pub line: usize,
    pub child_count: Option<usize>,
}
Expand description

Information about a parsed node (entity/row).

Represents a single entity parsed from a HEDL matrix row. Contains the entity’s type, ID, field values, and parent relationship information.

§Field Access

Fields can be accessed by index using get_field(). The first field (index 0) is always the ID.

§Examples

§Accessing Fields

use hedl_stream::{StreamingParser, NodeEvent};
use hedl_core::Value;
use std::io::Cursor;

let input = r#"
%VERSION: 1.0
%STRUCT: User: [id, name, email, active]
---
users:@User
  | alice, Alice Smith, alice@example.com, true
"#;

let parser = StreamingParser::new(Cursor::new(input))?;

for event in parser {
    if let Ok(NodeEvent::Node(node)) = event {
        // Access by index
        assert_eq!(node.get_field(0), Some(&Value::String("alice".to_string().into())));
        assert_eq!(node.get_field(1), Some(&Value::String("Alice Smith".to_string().into())));
        assert_eq!(node.get_field(3), Some(&Value::Bool(true)));

        // Or use the id field directly
        assert_eq!(node.id, "alice");
    }
}

§Checking Parent Relationships

use hedl_stream::{StreamingParser, NodeEvent};
use std::io::Cursor;

let input = r#"
%VERSION: 1.0
%STRUCT: User: [id, name]
%STRUCT: Order: [id, amount]
%NEST: User > Order
---
users:@User
  | alice, Alice
    | order1, 100.00
"#;

let parser = StreamingParser::new(Cursor::new(input))?;

for event in parser.filter_map(|e| e.ok()) {
    if let NodeEvent::Node(node) = event {
        if node.is_nested() {
            println!("{} is a child of {:?}",
                node.id, node.parent_id.as_ref().unwrap());
        }
    }
}

Fields§

§type_name: String

The entity type name.

§id: String

The entity ID.

§fields: Vec<Value>

Field values aligned with schema.

§depth: usize

Nesting depth (0 = top-level).

§parent_id: Option<String>

Parent node ID (if nested).

§parent_type: Option<String>

Parent type name (if nested).

§line: usize

Line number in source.

§child_count: Option<usize>

Expected child count from |[N] syntax.

Implementations§

Source§

impl NodeInfo

Source

pub fn new( type_name: String, id: String, fields: Vec<Value>, depth: usize, line: usize, ) -> Self

Create a new node info.

Source

pub fn with_parent(self, parent_type: String, parent_id: String) -> Self

Set parent information.

Source

pub fn with_child_count(self, count: usize) -> Self

Set expected child count from |[N] syntax.

Source

pub fn get_field(&self, index: usize) -> Option<&Value>

Get a field value by column index.

Source

pub fn is_nested(&self) -> bool

Check if this is a nested (child) node.

Trait Implementations§

Source§

impl Clone for NodeInfo

Source§

fn clone(&self) -> NodeInfo

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NodeInfo

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.