Downcast traits inside Rc for AST manipulation
问题 I'm trying to manipulate ASTs in Rust. There will be lots of manipulations, and I want my trees to be immutable, so to save time all references will be Rc s. My tree nodes will look like this: enum Condition { Equals(Rc<Expression>, Rc<Expression>), LessThan(Rc<Expression>, Rc<Expression>), ... } enum Expression { Plus(Rc<Expression>, Rc<Expression>), ... } I want to replace a random node of a given type with another node of the same type. To do generic operations on trees I've made a trait: