3 ms·
Yeah I think this is "Deref coercion" in Rust.[0] For example since Vec can Deref to Slice, you can syntactically run Slice methods on a Vec; meaning Vec is a
by meltyness 2y ago
Yeah I think this is "Deref coercion" in Rust.[0]
For example since Vec can Deref to Slice, you can syntactically run Slice methods on a Vec; meaning Vec is a subtype of Slice.
[0] https://doc.rust-lang.org/std/ops/trait.Deref.html#deref-coercion https://doc.rust-lang.org/std/ops/trait.Deref.html#deref-coe...
- meltyness 2y agoAs I revisit, this also comes up more explicitly when dealing with lifetimes as a type, and stacked borrows. [0] https://doc.rust-lang.org/nomicon/subtyping.html https://doc.rust-lang.org/nomicon/subtyping.html
- steveklabnik 2y agoLifetimes are the only subtyping relationship in Rust, yes.