You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any design for this issue will interact with other issues tracked by #885; make sure to read that issue when tackling this one.
Without generic_const_exprs, we can't use size_of::<T>() or align_of::<T>() in a generic context. We have many use cases for these, so it would be good to work around the issue with a sort of polyfill.
In general, we'd like to be able to express in the type system:
size_of::<T>() == size_of::<U>()
align_of::<T>() >= align_of::<U>() (useful for reference transmutations from T to U)
The most obvious approach is to add machinery to KnownLayout, although we need this machinery to not rely on const generics (like the associated LAYOUT type currently does), so it would need to be a true type-level representation. It might be the case that:
There are types we want to support which KnownLayout can't
There are types which KnownLayout currently supports which can't support this approach
Thus, we may need to introduce a separate trait or traits.
Given that the knowledge is now encoded in the type system, we need some way of expressing bounds. In other words, we need some sort of:
T: SizeEq<U>
T: AlignGtEq<U>
T: SizeEqConst<N>
T: AlignGtEqConst<N>
These could either be blanket impls in terms of KnownLayout, or be separate from KnownLayout entirely (and might need to be derived).
Any design for this issue will interact with other issues tracked by #885; make sure to read that issue when tackling this one.
Without generic_const_exprs, we can't use
size_of::<T>()
oralign_of::<T>()
in a generic context. We have many use cases for these, so it would be good to work around the issue with a sort of polyfill.In general, we'd like to be able to express in the type system:
size_of::<T>() == size_of::<U>()
align_of::<T>() >= align_of::<U>()
(useful for reference transmutations fromT
toU
)size_of::<T>() == N
align_of::<T>() >= N
or<= N
(to support Support eliding alignment check when reading from aligned buffer #280)API
The most obvious approach is to add machinery to
KnownLayout
, although we need this machinery to not rely on const generics (like the associatedLAYOUT
type currently does), so it would need to be a true type-level representation. It might be the case that:KnownLayout
can'tKnownLayout
currently supports which can't support this approachThus, we may need to introduce a separate trait or traits.
Given that the knowledge is now encoded in the type system, we need some way of expressing bounds. In other words, we need some sort of:
T: SizeEq<U>
T: AlignGtEq<U>
T: SizeEqConst<N>
T: AlignGtEqConst<N>
These could either be blanket impls in terms of
KnownLayout
, or be separate fromKnownLayout
entirely (and might need to be derived).Merging #125 into this:
The text was updated successfully, but these errors were encountered: