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
impl NormalizedNode
Sourcepub const fn with_children(kind: NodeKind, children: Vec<Self>) -> Self
pub const fn with_children(kind: NodeKind, children: Vec<Self>) -> Self
Create a node with children.
Sourcepub fn opt(node: Option<Self>) -> Self
pub fn opt(node: Option<Self>) -> Self
Convert an Option<NormalizedNode> to a node, using the Self::none sentinel for
absent values.
Trait Implementations§
Source§impl Clone for NormalizedNode
impl Clone for NormalizedNode
Source§impl Debug for NormalizedNode
impl Debug for NormalizedNode
impl Eq for NormalizedNode
Source§impl Hash for NormalizedNode
impl Hash for NormalizedNode
Source§impl PartialEq for NormalizedNode
impl PartialEq 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.