Function constmuck::wrapper::peel_slice[][src]

pub const fn peel_slice<Outer, Inner>(
    reff: &[Outer],
    _bound: IsTransparentWrapper<Outer, Inner>
) -> &[Inner]
Expand description

Casts &[Outer] to &[Inner]

Requires that Outer implements TransparentWrapper<Inner>

Example

use constmuck::{IsTW, 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]`
//
// `IsTW!()` is a more concise way to write `IsTransparentWrapper::NEW`
const X: &[&str] = wrapper::peel_slice(&[Bar("hello"), Bar("world")], IsTW!());

assert_eq!(X, ["hello", "world"]);