Skip to content

Comment on Rust Any part 3: we have upcastsparent

Comments

That doesn't add Foo's methods to Bar's list of methods, like you might expect from the term "inheritance".

This is not completly correct. It's true you won't e.g. be able to implement `Foo` and specify `Bar`'s method in it, however it does mean that e.g. `dyn Foo` will support `Bar`'s methods.

Despite this it's still accurate to say that this enables a supertype/subtype relationship in certain contexts

It does enable something that looks like subtyping because you're allowed to use something that implements `Foo` when something that implements `Bar` is expected. However this is not called subtyping in Rust terms; subtyping in Rust exists but is unrelated to traits (it's only affected by lifetimes)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.