In an interface/class hierarchy A < B < C, C can be an abstract class that only implements B’s methods and not A’s.
In an interface/class hierarchy A < B < C, C can be an abstract class that only implements B’s methods and not A’s.
Prior to the current version of Rust it was impossible to access methods on `Foo` when a `&dyn Bar` was passed. With the current beta version you can upcast.
This has been working since Rust 1.0, I think:
trait Foo {
fn foo(&self);
}
trait Bar : Foo {}
impl Foo for () {
fn foo(&self) { println!("Hello") }
}
impl Bar for () {}
fn xxx(x: &dyn Bar) {
x.foo();
}
pub fn main() {
xxx(&());
}
> With the current beta version you can upcastRight. Now you can convert from `&dyn Bar` to `&dyn Foo` which wasn't possible before.
I've experienced a lot of fear in other people, especially when interviewing, about Rust not being OOP. Very smart people seem to be coming up with carve-outs to keep that religion alive. Try letting go of OOP for a month or two, and you'll find that you're better off letting OOP be someone else's problem.
Remember, when people talk about "OOP" what they're actually talking about is Java EE 6.