NodeCollector

Struct NodeCollector 

Source
pub struct NodeCollector { /* private fields */ }
Expand description

Visitor that collects all nodes of a specific type.

§Example

use hedl_core::visitor::{utils::NodeCollector, traverse, TraversalConfig};
use hedl_core::{Document, Node};

let doc = Document::new((1, 0));
let mut collector = NodeCollector::new("User");
traverse(&doc, &mut collector, &TraversalConfig::default());
let users = collector.into_nodes();

Implementations§

Source§

impl NodeCollector

Source

pub fn new_all() -> Self

Create a collector for all nodes.

Source

pub fn new(type_name: impl Into<String>) -> Self

Create a collector for a specific node type.

Source

pub fn nodes(&self) -> &[Node]

Get the collected nodes.

Source

pub fn into_nodes(self) -> Vec<Node>

Consume the collector and return collected nodes.

Source

pub fn count(&self) -> usize

Get the count of collected nodes.

Trait Implementations§

Source§

impl Debug for NodeCollector

Source§

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

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

impl Visitor for NodeCollector

Source§

fn visit_node( &mut self, node: &Node, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called when visiting a node (row) in a list. Read more
Source§

fn begin_document( &mut self, _doc: &Document, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called at the start of document traversal. Read more
Source§

fn end_document( &mut self, _doc: &Document, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called at the end of document traversal. Read more
Source§

fn visit_scalar( &mut self, _key: &str, _value: &Value, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called when visiting a scalar value. Read more
Source§

fn begin_object( &mut self, _key: &str, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called before visiting an object’s children. Read more
Source§

fn end_object(&mut self, _key: &str, _ctx: &VisitorContext<'_>) -> VisitDecision

Called after visiting an object’s children.
Source§

fn begin_list( &mut self, _key: &str, _list: &MatrixList, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called before visiting a list’s rows. Read more
Source§

fn end_list( &mut self, _key: &str, _list: &MatrixList, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called after visiting a list’s rows.
Source§

fn begin_node_children( &mut self, _node: &Node, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called before visiting a node’s children. Read more
Source§

fn end_node_children( &mut self, _node: &Node, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called after visiting a node’s children.
Source§

fn visit_reference( &mut self, _reference: &Reference, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called when visiting a reference value. Read more
Source§

fn visit_expression( &mut self, _expr: &Expression, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called when visiting an expression value. Read more
Source§

fn visit_tensor( &mut self, _tensor: &Tensor, _ctx: &VisitorContext<'_>, ) -> VisitDecision

Called when visiting a tensor value. 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> 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, 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.