Skip to main content

NormalizedNode

Struct NormalizedNode 

Source
pub struct NormalizedNode {
    pub kind: NodeKind,
    pub children: Vec<Self>,
}
Expand description

A normalized AST node. Uses a data-driven { kind, children } representation instead of a large enum with differently-shaped variants. This allows generic traversal algorithms (count_nodes, reindex, count_matching, extract) to work without exhaustive matching on every variant.

§Child ordering conventions

  • Fixed with None sentinels (always same child count):
    • If -> [condition, then_branch, else_or_None]
    • LetBinding -> [pattern, type_or_None, init_or_None, diverge_or_None]
    • Range / PatRange -> [from_or_None, to_or_None]
    • MatchArm -> [pattern, guard_or_None, body]
  • Fixed children first, variable after (for zip alignment):
    • Call -> [func, arg0, arg1, …]
    • MethodCall -> [receiver, method, arg0, …]
    • Closure -> [body, param0, …]
    • FnSignature -> [return_type_or_None, param0, …]
    • Match -> [expr, arm0, arm1, …]
    • StructInit -> [rest_or_None, field0, field1, …]
    • MacroCall -> [arg0, arg1, …]
  • Variable-length (0 or 1): Return, Break -> [] or [value]
  • Homogeneous: Block, Tuple, Array, Path, PatTuple, etc. -> [elem0, …]
  • All other fixed: e.g. BinaryOp -> [left, right], ForLoop -> [pat, iter, body]

Fields§

§kind: NodeKind§children: Vec<Self>

Implementations§

Source§

impl NormalizedNode

Source

pub const fn leaf(kind: NodeKind) -> Self

Create a leaf node (no children).

Source

pub const fn with_children(kind: NodeKind, children: Vec<Self>) -> Self

Create a node with children.

Source

pub const fn none() -> Self

Create a None sentinel node.

Source

pub fn opt(node: Option<Self>) -> Self

Convert an Option<NormalizedNode> to a node, using the Self::none sentinel for absent values.

Source

pub const fn is_none(&self) -> bool

Check if this is a None sentinel node.

Trait Implementations§

Source§

impl Clone for NormalizedNode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for NormalizedNode

Source§

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

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

impl Eq for NormalizedNode

Source§

impl Hash for NormalizedNode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for NormalizedNode

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NormalizedNode

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.