Open
Description
Owned slices can be cast with fewer restrictions than mutably borrowed ones, because the cast doesn't have to be reversible. This issue is a request for two features:
try_cast_boxed_slice
: castsBox<[A]>
toBox<[B]>
if they have the same layout and B isAnyBitPattern
.convert_boxed_slice
: convertsBox<[A]>
toBox<[B]>
if they have the same layout, and takes aFn(A) -> B
parameter. (Could be implemented by first casting to a slice of a union type.)
An example use case for convert_box_slice
would be to create a safe version of this function, although it would also require ColorU8
, the output type, to implement AnyBitPattern
. Note that the input type PremultipliedColorU8
cannot implement AnyBitPattern
, since it has the invariant that no color byte has a larger value than the alpha byte. ColorU8
can implement AnyBitPattern
but doesn't.
Metadata
Metadata
Assignees
Labels
No labels