Function constmuck::wrapper::peel_slice [−][src]
pub const fn peel_slice<Inner, Outer>(
reff: &[Outer],
_: ImplsTransparentWrapper<Outer, Inner>
) -> &[Inner]
Expand description
Casts &[Outer]
to &[Inner]
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 `&[Bar<&str>]` to `&[&str]`
//
// `infer_tw!()` is a more concise way to write `ImplsTransparentWrapper::NEW`
const X: &[&str] = wrapper::peel_slice(&[Bar("hello"), Bar("world")], infer_tw!());
assert_eq!(X, ["hello", "world"]);