-
Notifications
You must be signed in to change notification settings - Fork 137
Description
A number of desired features require knowledge of the recursive layout of a type down to individual fields. KnownLayout is not recursive (e.g. you can derive KnownLayout on a sized type whose fields are not KnownLayout), and so we cannot use KnownLayout without a semver breaking change. Besides, KnownLayout is philosophically the wrong place for these features.
These features include:
- In-place initialization (Support incremental in-place initialization #2749)
- Field projection (Support field projection in any
#[repr(transparent)]wrapper type #196) - Zeroing padding (Provide the ability to zero padding bytes and return
&Initialized<T>#494) - Access to a value's initialized prefix (Retrieving prefix bytes of types with trailing padding #2668)
Instead, we should add a super-trait to TryFromBytes which has a recursive requirement (just like TryFromBytes) but which is not as heavy-weight as TryFromBytes (which requires deriving an entire validator) and does not expose the ability to construct a type to users outside of a module (which is something that an author may wish to avoid). Naming TBD (Initialize and Inhabited were both proposed, but other names may be better).
Open questions
- Could we migrate any functionality from
KnownLayout, thus unlocking this functionality a) as a dependency of this new trait or, b) for types whichKnownLayoutcan't support?