Function constmuck::wrapper::peel_ref [−][src]
pub const fn peel_ref<Outer, Inner>(
reff: &Outer,
_bound: IsTransparentWrapper<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::{IsTW, 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`
//
// `IsTW!()` is a more concise way to write `IsTransparentWrapper::NEW`
const X: &char = wrapper::peel_ref(&Foo('@'), IsTW!());
assert_eq!(X, &'@');