Function constmuck::wrapper::peel_ref[][src]

pub const fn peel_ref<Inner, Outer>(
    reff: &Outer,
    _: ImplsTransparentWrapper<Outer, Inner>
) -> &Inner
Expand description

Casts &Outer to &Inner

Requires that Outer implements TransparentWrapper<Inner>

To cast references to ?Sized types, you need to use the peel_ref macro instead of this function.

Example

use constmuck::{infer_tw, wrapper};

#[derive(Debug, PartialEq)]
#[repr(transparent)]
pub struct Foo<T>(pub T);

unsafe impl<T> constmuck::TransparentWrapper<T> for Foo<T> {}

// Casting `&Foo<char>` to `&char`
//
// `infer_tw!()` is a more concise way to write `ImplsTransparentWrapper::NEW`
const X: &char = wrapper::peel_ref(&Foo('@'), infer_tw!());

assert_eq!(X, &'@');