Open kupiakos opened 10 months ago
These could also work, but there are likely conflicting blanket impls for these to all be From
methods:
<T: ?Sized + AsMaybeUninit>(&MaybeUninit<T>) -> &[MaybeUninit<u8>]
<T: ?Sized + AsMaybeUninit>(&mut MaybeUninit<T>) -> &mut [MaybeUninit<u8>]
<T: ?Sized + AsMaybeUninit>(&mut MaybeUninit<T>) -> Out<[u8]>
MaybeUninit
, and no uninit bytes are exposed by the Out
. This is the mutable version of the above.<T: ?Sized, U>(&mut MaybeUninit<T>) -> Option<Out<U>>
<T: FromBytes + ?Sized, U: AsBytes + FromBytes>(Out<T>) -> Option<Out<U>>
U: AsBytes
makes it so write
ing a U
cannot write uninit that is invalid for T
T
could be unaligned for U
<T: FromBytes + ?Sized, U: AsBytes + FromBytes>(Out<T>) -> Option<Out<U>>
U: AsBytes
makes it so write
ing a U
cannot write uninit that is invalid for T
T
could be unaligned for U
<T: FromBytes + ?Sized, U: AsBytes + FromBytes + Unaligned>(Out<T>) -> Out<U>
U: AsBytes
makes it so write
ing a U
cannot write uninit that is invalid for T
U
cannot have a stricter alignment requirement than T
The most flexible and simple of these is the Out<T: ?Sized + FromBytes> -> Out<[u8]>
conversion. The rest either involve Unaligned
bounds or dynamic alignment checks.
Gated by a non-default feature.
<T: FromBytes + ?Sized>(&mut T) -> Out<[u8]>
AsBytes
is not required as it is for&mut T -> &mut [u8]
since theOut
does not expose uninitialized bytes<T: FromBytes + ?Sized>(Out<T>) -> Out<[u8]>
mem::size_of_val
should work here?