#![allow(dead_code)] use uniplate::derive::Uniplate; use uniplate::Biplate; #[derive(Eq, PartialEq, Clone, Debug, Uniplate)] #[uniplate()] #[biplate(to=String,walk_into=[Expr])] enum Stmt { Nothing, Assign(String, Expr), Sequence(Vec), If(Expr, Box, Box), While(Expr, Box), } #[derive(Eq, PartialEq, Clone, Debug, Uniplate)] #[uniplate()] #[biplate(to=String)] enum Expr { Add(Box, Box), Sub(Box, Box), Mul(Box, Box), Div(Box, Box), Val(i32), Var(String), Neg(Box), } pub fn main() { use Expr::*; use Stmt::*; let stmt_1 = Assign("x".into(), Div(Box::new(Val(2)), Box::new(Var("y".into())))); let strings_in_stmt_1 = >::universe_bi(&stmt_1); // Test multi-type traversals assert_eq!(strings_in_stmt_1.len(), 2); assert!(strings_in_stmt_1.contains(&"x".into())); assert!(strings_in_stmt_1.contains(&"y".into())); }