Add `Initialize`/`Inhabited` (`TryFromBytes` super-trait)
- Dominant language
- Rust
- Stars
- 2.6k
- Forks
- 179
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 29
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 (#2749)
- Field projection (#196)
- Zeroing padding (#494)
- Access to a value's initialized prefix (#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 which `KnownLayout` can't support?
Contributor guide
Assessment
This issue has not been assessed yet.