Open
Description
Add a new Node
union that is an enum over all node types. This can be useful when implementing methods that can operate on any node. For example, Ruff's formatter has (roughly) the API format(node: AnyNode) -> String
I haven't figured out the full requirements yet, and I don't know yet if we'll need both the owned and reference versions:
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
enum Node {
IfStmt(ast::IfStmt),
ConstantExpr(ast::ConstantExpr),
...
}
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, is_macro)]
enum NodeRef<'a> {
IfStmt(&'a ast::IfStmt),
ConstantExpr(&'a ast::ConstantExpr)
...
}
Note: An alternative naming more in line with
Path
andPathBuf
would be to name the typesNodeBuf
(owned) andNode
(reference)
The enums should have the following basic methods:
if_stmt(self) -> Option<ast::IfStmt>
as_if_stmt(&self) -> Option<&ast::IfStmt>
const is_if_stmt(&self) -> bool
Node could also implement AsRef
that returns a NodeRef
I may have time to work on this sometime soon but I wanted to put this up for discussion first to get feedback.
Metadata
Metadata
Assignees
Labels
No labels