- Feature Name:
dyn_type - Start Date: 2018-01-04
- RFC PR: (leave this empty)
- Rust Issue: (leave this empty)
Summary
Generalize the concept of Dynamic Sized Types (DSTs) and enable custom DSTs.
Motivation
This RFC is a replacement of RFC #1524. The main motivations of custom DSTs are:
-
DST allows us to get rid of combinatorial explosion when interacting with smart pointers. Instead of defining
BoxMatrix,RcMatrix,GcMatrixetc, we getBox<Matrix>,Rc<Matrix>,Gc<Matrix>from a single type. -
The
IndexandDereftrait requires us to return a reference without allocation, i.e. indexing operation can’t return aMatrixRef<'a>even if this is the only solution without custom DST. -
Allow more possibilities for modifying existing APIs involving DST types without breakage.
We expect many types will benefit from custom DSTs, here are some examples:
- Multi-dimensional arrays (matrix and tensor libraries).
- Length-prefixed structures e.g. Pascal strings or C structures with a flexible array member.
CStr.- Multi-encoded string.
- Bit array.
Guide-level explanation
Reference-level explanation
Drawbacks
Rationale and alternatives
Unresolved questions
- Currently all super-traits of
Sized(i.e.Aligned,DynSized, andObject) are marked#[fundamental], but it is unclear whether we really need this attribute on them.