mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-29 10:31:14 -03:00
ast: factor out as_node
Shrink another macro.
This commit is contained in:
15
src/ast.rs
15
src/ast.rs
@@ -97,7 +97,7 @@ fn accept_mut(&mut self, visitor: &mut dyn NodeVisitorMut, reversed: bool) {
|
||||
}
|
||||
|
||||
/// Node is the base trait of all AST nodes.
|
||||
pub trait Node: Acceptor + ConcreteNode + std::fmt::Debug {
|
||||
pub trait Node: Acceptor + ConcreteNode + AsNode + std::fmt::Debug {
|
||||
/// The type of this node.
|
||||
fn typ(&self) -> Type;
|
||||
|
||||
@@ -154,11 +154,19 @@ fn source<'s>(&self, orig: &'s wstr) -> &'s wstr {
|
||||
fn self_memory_size(&self) -> usize {
|
||||
std::mem::size_of_val(self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Convert to the dynamic Node type.
|
||||
// Convert to the dynamic Node type.
|
||||
pub trait AsNode {
|
||||
fn as_node(&self) -> &dyn Node;
|
||||
}
|
||||
|
||||
impl<T: Node + Sized> AsNode for T {
|
||||
fn as_node(&self) -> &dyn Node {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if two nodes are the same object.
|
||||
#[inline(always)]
|
||||
pub fn is_same_node(lhs: &dyn Node, rhs: &dyn Node) -> bool {
|
||||
@@ -519,9 +527,6 @@ impl Node for $name {
|
||||
fn typ(&self) -> Type {
|
||||
Type::$type
|
||||
}
|
||||
fn as_node(&self) -> &dyn Node {
|
||||
self
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user