Function constmuck::wrapper::wrap_slice [−][src]
pub const fn wrap_slice<Inner, Outer>(
reff: &[Inner],
_: ImplsTransparentWrapper<Outer, Inner>
) -> &[Outer]
Expand description
Casts &[Inner]
to &[Outer]
Requires that Outer
implements
TransparentWrapper<Inner>
Example
use constmuck::{infer_tw, wrapper};
#[derive(Debug, PartialEq)]
#[repr(transparent)]
pub struct Bar<T>(pub T);
unsafe impl<T> constmuck::TransparentWrapper<T> for Bar<T> {}
// Casting `&[&str]` to `&[Bar<&str>]`
//
// `infer_tw!()` is a more concise way to write `ImplsTransparentWrapper::NEW`
const X: &[Bar<&str>] = wrapper::wrap_slice(&["hello", "world"], infer_tw!());
assert_eq!(X, [Bar("hello"), Bar("world")]);
// `infer_tw!(Bar<_>)` is required because any type can implement comparison with `Bar`.
assert_eq!(
wrapper::wrap_slice(&["hello", "world"], infer_tw!(Bar<_>)),
[Bar("hello"), Bar("world")],
);