Originally posted by atomsymbol
View Post
Like if you want a function that operates on something that implements/"inherits" a class/interface/trait that implements addition, you'd do something like:
Code:
fn do_thing<T: Add>(x : &T, y :&T) -> T { x + y }
Obviously, you could also just implement functions directly with structs without needing traits and call those functions in a way consistent with other OO languages. But that's not very interesting by itself. Traits is what really gives Rust the ability to do interesting things with objects.
See also the HasArea example in the Rust book:
https://doc.rust-lang.org/book/traits.html
Comment