[][src]Trait ref_cast::RefCast

pub trait RefCast {
    type From: ?Sized;
    fn ref_cast(from: &Self::From) -> &Self;
fn ref_cast_mut(from: &mut Self::From) -> &mut Self; }

Safely cast &T to &U where the struct U contains a single field of type T.

// `&String` can be cast to `&U`.
#[derive(RefCast)]
#[repr(C)]
struct U(String);

// `&T` can be cast to `&V<T>`.
#[derive(RefCast)]
#[repr(C)]
struct V<T> {
    t: T,
}

See the crate-level documentation for usage examples!

Associated Types

Loading content...

Required methods

Loading content...

Implementors

Loading content...