I assume the compiler suggests you replace @Expr with Rc<Expr> (Rc is defined in std::rc). This means you wouldn't be able to create cycles (that is, expressions must form a tree, or at most a DAG), and that there would be the overhead of reference counting when you create new expressions, clone the pointers to them etc.; on the other hand, there wouldn't be any GC involved.
On Mon, Oct 28, 2013 at 6:40 PM, Ramakrishnan Muthukrishnan < vu3...@gmail.com> wrote: > Hello rust hackers, > > In section 8.1.7 of the Rust manual ("Recursive types"), there is an > example of a List definition which is recursive. Here I define a very > simple arithmetic expression which consists of numbers and add > expressions. When I compile it I get errors.. > > enum Expr > { > Num(int), > Add(@Expr, @Expr), > } > > fn eval(e: Expr) -> int { > match e { > Num(x) => x, > Add(x, y) => eval(x) + eval(y), > } > } > > fn main() { > println(format!("eval 2 = {:d}", eval(Num(2)))); > println(format!("eval 2 + 3 = {:d}", eval(Add(Num(2), Num(3))))); > } > > $ rustc arith.rs > arith.rs:4:8: 4:13 error: The managed box syntax may be replaced by a > library type, and a garbage collector is not yet implemented. Consider > using the `std::rc` module as it performs much better as a reference > counting implementation. > arith.rs:4 Add(@Expr, @Expr), > ^~~~~ > arith.rs:4:8: 4:13 note: add #[feature(managed_boxes)] to the crate > attributes to enable > arith.rs:4 Add(@Expr, @Expr), > ^~~~~ > arith.rs:4:15: 4:20 error: The managed box syntax may be replaced by a > library type, and a garbage collector is not yet implemented. Consider > using the `std::rc` module as it performs much better as a reference > counting implementation. > arith.rs:4 Add(@Expr, @Expr), > ^~~~~ > arith.rs:4:15: 4:20 note: add #[feature(managed_boxes)] to the crate > attributes to enable > arith.rs:4 Add(@Expr, @Expr), > ^~~~~ > error: aborting due to 2 previous errors > > I am running rust from master. What exactly is the compiler suggesting > me to do? How can `std::rc' module help in this situation? > > TIA > -- > Ramakrishnan > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev