ref-cast 1.0.25

Safely cast &T to &U where the struct U contains a single field of type T.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use ref_cast::{ref_cast_custom, RefCastCustom};

#[derive(RefCastCustom)]
#[repr(transparent)]
pub struct Thing(str);

impl Thing {
    #[ref_cast_custom]
    pub fn ref_cast(s: impl AsRef<str>) -> &Self;

    #[ref_cast_custom]
    pub fn ref_cast2(s: &impl AsRef<str>) -> &Self;
}

fn main() {}