Skip to main content

Node

Struct Node 

Source
pub struct Node {
    pub type_name: String,
    pub id: String,
    pub fields: SmallVec<[Value; 4]>,
    pub children: Option<Box<BTreeMap<String, Vec<Node>>>>,
    pub child_count: u16,
}
Expand description

A node in a matrix list.

§Memory Layout Optimizations

Size reduced from ~120 bytes to ~80 bytes per node:

  • fields: Uses SmallVec to inline up to 4 values (typical case)
  • children: Lazy allocation - None until first child added (saves 24 bytes for leaf nodes)
  • child_count: Uses u16 (2 bytes) with 0 = no hint (vs 16 bytes for Option<usize>)

For 10,000 nodes: ~400KB saved in struct overhead alone.

Fields§

§type_name: String

The type name (from schema). During parsing, this can be interned to share memory across all nodes of same type.

§id: String

The node’s ID (first column value).

§fields: SmallVec<[Value; 4]>

Field values (aligned with schema columns). SmallVec avoids heap allocation for ≤4 fields (common case: 90%+ of nodes).

§children: Option<Box<BTreeMap<String, Vec<Node>>>>

Child nodes grouped by type (from NEST relationships). Lazy allocation - None until first child added. ~70% of nodes are leaves.

§child_count: u16

Count of direct children (for LLM comprehension hints). 0 = no hint provided. Max 65,535 children (sufficient for all practical cases).

Implementations§

Source§

impl Node

Source

pub fn new( type_name: impl Into<String>, id: impl Into<String>, fields: Vec<Value>, ) -> Self

Create a new node.

Source

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

Get a field value by column index.

Source

pub fn add_child(&mut self, child_type: impl Into<String>, child: Node)

Add a child node. Uses lazy allocation - children BTreeMap is only created on first add.

Source

pub fn set_child_count(&mut self, count: usize)

Set the child count hint (for LLM comprehension). Saturates at u16::MAX (65,535) if count exceeds.

Source

pub fn get_child_count(&self) -> Option<usize>

Get the child count hint, if provided.

Source

pub fn with_child_count( type_name: impl Into<String>, id: impl Into<String>, fields: Vec<Value>, child_count: usize, ) -> Self

Create a new node with a child count hint.

§Arguments
  • type_name: The type name from the schema
  • fields: Field values where fields[0] MUST be the node ID (a string)
  • child_count: Expected number of children (for LLM hints)
Source

pub fn children(&self) -> Option<&BTreeMap<String, Vec<Node>>>

Get the children map, if any children have been added.

Source

pub fn children_mut(&mut self) -> Option<&mut BTreeMap<String, Vec<Node>>>

Get mutable access to children map, if it exists.

Trait Implementations§

Source§

impl Clone for Node

Source§

fn clone(&self) -> Node

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 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() -> Self

Returns the “default value” for a type. Read more
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 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 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.