pub struct NormalizedNode {
pub kind: NodeKind,
pub children: Vec<NormalizedNode>,
}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<NormalizedNode>Implementations§
Source§impl NormalizedNode
impl NormalizedNode
Sourcepub const fn leaf(kind: NodeKind) -> NormalizedNode
pub const fn leaf(kind: NodeKind) -> NormalizedNode
Create a leaf node (no children).
Sourcepub const fn with_children(
kind: NodeKind,
children: Vec<NormalizedNode>,
) -> NormalizedNode
pub const fn with_children( kind: NodeKind, children: Vec<NormalizedNode>, ) -> NormalizedNode
Create a node with children.
Sourcepub const fn none() -> NormalizedNode
pub const fn none() -> NormalizedNode
Create a None sentinel node.
Sourcepub fn opt(node: Option<NormalizedNode>) -> NormalizedNode
pub fn opt(node: Option<NormalizedNode>) -> NormalizedNode
Convert an Option
Trait Implementations§
Source§impl Clone for NormalizedNode
impl Clone for NormalizedNode
Source§fn clone(&self) -> NormalizedNode
fn clone(&self) -> NormalizedNode
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for NormalizedNode
impl Debug for NormalizedNode
Source§impl Hash for NormalizedNode
impl Hash for NormalizedNode
Source§impl PartialEq for NormalizedNode
impl PartialEq for NormalizedNode
impl Eq for NormalizedNode
impl StructuralPartialEq for NormalizedNode
Auto Trait Implementations§
impl Freeze for NormalizedNode
impl RefUnwindSafe for NormalizedNode
impl Send for NormalizedNode
impl Sync for NormalizedNode
impl Unpin for NormalizedNode
impl UnsafeUnpin for NormalizedNode
impl UnwindSafe for NormalizedNode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.