To clarify I meant subtyping in the sense of when are types compatible for some kind of conversion. As opposed to subsumption or subclassing (or at least, not limited to these cases).
If I have |e as U| when does that succeed, and when does it fail. (Actually from the manual it was unclear how much checking is done statically vs dynamically, but that is kind of a tangent). Presumably the cast only succeeds if the dynamic type of e is a subtype of U (or it can be coerced or converted to U). An example from the manual (sect 8.1.10) shows that an instance of an impl can be cast to the type of an implemented trait, are there other relationships where casting is allowed? The manual states (sect 7.2.11.5): "A numeric value can be cast to any numeric type. A raw pointer value can be cast to or from any integral type or raw pointer type. Any other cast is unsupported and will fail to compile." But the last sentence is contradicted by the example in section 8.1.10 Separately, I remember that the various pointer types can be implicitly converted. I couldn't find anywhere where these conversions are defined. Is my memory bad or my search skills? Thanks, Nick On Tue, Sep 10, 2013 at 1:34 AM, Niko Matsakis <[email protected]> wrote: > By subtyping, do you mean defining class hierarchies as in C++ or > Java? This is currently not supported. Typically such hierarchies > are modeled either using an `enum` (most common) or using a `trait`. > > Enums are perfect for cases where there is a limited set of > possibilities. Traits are perfect for "open-ended" situations where > you have an interface and many ways to fulfill it. The two techniques > *can* be combined for cases that fall between the two extremes. > > We have considered adding a limited form of struct inheritance (so > that one struct can build on another) but afaik this feature is not > planned in the short term. > > > Niko > > On Mon, Sep 09, 2013 at 07:04:07PM +1200, Nick Cameron wrote: > > Is there somewhere I can look for a description of subtyping in Rust? I > > don't see any mention of it in the manual or tutorial. > > > > Thanks, Nick > > > _______________________________________________ > > Rust-dev mailing list > > [email protected] > > https://mail.mozilla.org/listinfo/rust-dev > >
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
