I believe that was just showing an example of the error the compiler will generate when not using trait constraints. If you read a little further, a similar error is produced from
fn print_area<T>(shape: T) { println!("This shape has an area of {}", shape.area()); } Because T can be any type, we can't be sure that it implements the area method. But we can add a *trait constraint* to our generic T, ensuring that it does: fn print_area<T: HasArea>(shape: T) { println!("This shape has an area of {}", shape.area()); } If you're wanting to do comparisons, you will probably want to place a trait constraint on your functions from the following module: http://doc.rust-lang.org/std/cmp/index.html#traits Nathan Sizemore @nathansizemore | 937.823.7229 On Fri, Dec 5, 2014 at 6:33 AM, Péter Mózes Merl <m...@mage.li> wrote: > Hi Everyone, > > after long years of working with scripting languages I have finally found > a strongly-typed language that is worth to learn (for me). Cheers. > > The Guide is awesome. There is only one thing I missed and that’s between > chapters 22 and 23, Generics and Traits. The Guide says that we have to > learn about Traits to fix this message: > > error: binary operation `==` cannot be applied to type `T` > > I think the example how to fix it at the end is missing. I am not sure > whether this is the right place to provide such a feedback, however, I > could not find a link in the Guide. > > Thank you. > > Péter > > _______________________________________________ > 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