Trait core_extensions::transparent_newtype::TransparentNewtype [−][src]
pub unsafe trait TransparentNewtype { type Inner: ?Sized; fn convert_from(v: Self::Inner) -> Self
where
Self: Sized,
Self::Inner: Sized, { ... } fn convert_ref_from(v: &Self::Inner) -> &Self { ... } fn convert_mut_from(v: &mut Self::Inner) -> &mut Self { ... } fn convert_into(self) -> Self::Inner
where
Self: Sized,
Self::Inner: Sized, { ... } fn convert_ref_to(&self) -> &Self::Inner { ... } fn convert_mut_to(&mut self) -> &mut Self::Inner { ... } }
Trait for newtypes which are safe to transmute to/from their contents.
Examples of such types:
-
#[repr(transparent)] types (stable since Rust 1.28).
-
Newtypes whose only non-zero sized field is T,in which the alignment is the same as T.
Safety,for implementors
The size and alignment of Self must be the same as T.
To ensure this trait is properly implemented for a newtype wrapping a T:
- don't use an align attribute:
- require that the types of the other fields implement MarkerType.
Safety,for users
Look at the module-level documentation
Associated Types
Provided Methods
fn convert_from(v: Self::Inner) -> Self where
Self: Sized,
Self::Inner: Sized,
Self: Sized,
Self::Inner: Sized,
Converts a T value to Self.
ⓘImportant traits for &'a mut R
fn convert_ref_from(v: &Self::Inner) -> &Self
Converts a reference to T to a reference to Self.
ⓘImportant traits for &'a mut R
fn convert_mut_from(v: &mut Self::Inner) -> &mut Self
Converts a mutable reference to T to a mutable reference to Self.
fn convert_into(self) -> Self::Inner where
Self: Sized,
Self::Inner: Sized,
Self: Sized,
Self::Inner: Sized,
Converts self to a T value.
fn convert_ref_to(&self) -> &Self::Inner
Converts a reference to Self to a reference to T.
fn convert_mut_to(&mut self) -> &mut Self::Inner
Converts a mutable reference to Self to a mutable reference to T.