3 ms·
Okay, but doesn't Bar nevertheless inherit Foo's methods in the sense of interface inheritance? Or does code that gets passed a Bar not get access to Foo's meth
by layer8 2y ago
Okay, but doesn't Bar nevertheless inherit Foo's methods in the sense of interface inheritance? Or does code that gets passed a Bar not get access to Foo's methods?
- the_mitsuhiko 2y ago> does code that gets passed a Bar not get access to Foo's methods 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.
- ogoffart 2y ago> Prior to the current version of Rust it was impossible to access methods on `Foo` when a `&dyn Bar` was passed. 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 upcast Right. Now you can convert from `&dyn Bar` to `&dyn Foo` which wasn't possible before.
- the_mitsuhiko 2y agoInherent method implementations were unavailable. (Eg: impl dyn Foo) and then call this via Bar.