Function constmuck::transmutable::transmute_slice [−][src]
pub const fn transmute_slice<T, U>(
value: &[T],
_bounds: TransmutableInto<T, U>
) -> &[U]
Expand description
Transmutes &[T]
into &[U]
, given a TransmutableInto
.
Example
use constmuck::{
transmutable::{TransmutableInto, transmute_slice},
infer, infer_tw,
};
use std::num::Wrapping;
// Transmuting from `&[u8]` to `&[i8]`
const SIGNED: &[i8] = transmute_slice(&[5u8, 250u8, 255u8], TransmutableInto::pod(infer!()));
assert_eq!(*SIGNED, [5, -6, -1]);
// Transmuting from `&[Wrapping<u8>]` to `&[i8]`
//
// `infer_tw!()` constructs an `ImplsTransparentWrapper`,
// whose `into_inner` field allows transmuting from a wrapper into the value in it.
const UNWRAPPED: &[u8] =
transmute_slice(&[Wrapping(5), Wrapping(250)], infer_tw!().into_inner);
assert_eq!(*UNWRAPPED, [5, 250]);
// Transmuting from `&[u8]` to `&[Wrapping<u8>]`
//
// `infer_tw!()` constructs an `ImplsTransparentWrapper`,
// whose `from_inner` field allows transmuting from a value into a wrapper around it.
const WRAPPED: &[Wrapping<u8>] = transmute_slice(&[7, 78], infer_tw!().from_inner);
assert_eq!(*WRAPPED, [Wrapping(7), Wrapping(78)]);