Trait core_extensions::transparent_newtype::TransparentNewtype[][src]

pub unsafe trait TransparentNewtype {
    type Inner: ?Sized;
    fn from_inner_raw(from: *const Self::Inner) -> *const Self;
fn from_inner_raw_mut(v: *mut Self::Inner) -> *mut Self;
fn as_inner_raw(from: *const Self) -> *const Self::Inner;
fn as_inner_raw_mut(this: *mut Self) -> *mut Self::Inner; }
This is supported on crate feature transparent_newtype only.
Expand description

Trait for #[repr(transparent)] newtypes, which are safe to transmute to/from their contents.

For additional conversion methods, you can use the TransparentNewtypeExt extension trait.


Implementors must only implement this trait for #[repr(transparent)] wrappers, with the same alignment as its only non-zero-sized field, and the type of that field must be used as the TransparentNewtype::Inner associated type.

This trait can be implemented with any of these macros:


A totally ordered 32 bit float.

use core_extensions::{TransparentNewtype, TransparentNewtypeExt};

pub struct TotalF32(pub f32);

// Eq, Ord, PartialEq, PartialOrd impls not shown

unsafe impl TransparentNewtype for TotalF32{
    type Inner = f32;

let mut list = vec![1.0, 0.0, 2.0];

<[TotalF32]>::from_inner_mut(&mut list).sort();

assert_eq!(list, vec![0.0, 1.0, 2.0]);

Associated Types

The wrapped type

Required methods

Converts *const Self::Inner to *const Self.

Converts *mut Self::Inner to *mut Self.

Converts *const Self to *const Self::Inner.

Converts *mut Self to *mut Self::Inner.

Implementations on Foreign Types