pub trait TransparentNewtypeExt: TransparentNewtype {
    fn from_inner(v: Self::Inner) -> Self
    where
        Self: Sized,
        Self::Inner: Sized
, { ... } fn from_inner_ref(v: &Self::Inner) -> &Self { ... } fn from_inner_mut(v: &mut Self::Inner) -> &mut Self { ... } fn from_inner_box(v: Box<Self::Inner>) -> Box<Self> { ... } fn from_inner_arc(v: Arc<Self::Inner>) -> Arc<Self> { ... } fn from_inner_rc(v: Rc<Self::Inner>) -> Rc<Self> { ... } fn into_inner(self) -> Self::Inner
    where
        Self: Sized,
        Self::Inner: Sized
, { ... } fn as_inner(&self) -> &Self::Inner { ... } fn as_inner_mut(&mut self) -> &mut Self::Inner { ... } fn into_inner_box(self: Box<Self>) -> Box<Self::Inner> { ... } fn into_inner_arc(self: Arc<Self>) -> Arc<Self::Inner> { ... } fn into_inner_rc(self: Rc<Self>) -> Rc<Self::Inner> { ... } }
Available on crate feature transparent_newtype only.
Expand description

Extension trait for TransparentNewtypes

Provided Methods

Converts Self::Inner to Self.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping::from_inner(3), Wrapping(3));
assert_eq!(ManuallyDrop::from_inner(5), ManuallyDrop::new(5));
 

Converts &Self::Inner to a &Self.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping::from_inner_ref(&3), &Wrapping(3));
assert_eq!(ManuallyDrop::from_inner_ref(&5), &ManuallyDrop::new(5));
 

Converts &mut Self::Inner to a &mut Self.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping::from_inner_ref(&mut 3), &mut Wrapping(3));
assert_eq!(ManuallyDrop::from_inner_ref(&mut 5), &mut ManuallyDrop::new(5));
 
Available on crate feature alloc only.

Converts Box<Self::Inner> to a Box<Self> without allocating.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop as MD;
 
assert_eq!(Wrapping::from_inner_box(Box::new(3)), Box::new(Wrapping(3)));
assert_eq!(MD::from_inner_box(Box::new(5)), Box::new(MD::new(5)));
 
Available on crate feature alloc only.

Converts Arc<Self::Inner> to a Arc<Self> without allocating.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop as MD;
use std::sync::Arc;
 
assert_eq!(Wrapping::from_inner_arc(Arc::new(3)), Arc::new(Wrapping(3)));
assert_eq!(MD::from_inner_arc(Arc::new(5)), Arc::new(MD::new(5)));
 
Available on crate feature alloc only.

Converts Rc<Self::Inner> to a Rc<Self> without allocating.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop as MD;
use std::rc::Rc;
 
assert_eq!(Wrapping::from_inner_rc(Rc::new(3)), Rc::new(Wrapping(3)));
assert_eq!(MD::from_inner_rc(Rc::new(5)), Rc::new(MD::new(5)));
 

Converts self to a Self::Inner.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping(3).into_inner(), 3);
assert_eq!(ManuallyDrop::new(5).into_inner(), 5);
 

Converts self to a &Self::Inner.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping(3).as_inner(), &3);
assert_eq!(ManuallyDrop::new(5).as_inner(), &5);
 

Converts self to a &mut Self::Inner.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Wrapping(3).as_inner_mut(), &mut 3);
assert_eq!(ManuallyDrop::new(5).as_inner_mut(), &mut 5);
 
Available on crate feature alloc only.

Converts self to a Box<Self::Inner> without allocating.

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
 
assert_eq!(Box::new(Wrapping(3)).into_inner_box(), Box::new(3));
assert_eq!(Box::new(ManuallyDrop::new(5)).into_inner_box(), Box::new(5));
 
Available on crate feature alloc only.

Converts self to a Arc<Self::Inner> without allocating.

Self parameter

Enabling the “rust_1_46” feature changes this method from taking a this parameter to taking a self parameter, which allows calling it with .into_inner_arc()

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
use std::sync::Arc;
 
assert_eq!(
    Wrapping::into_inner_arc(Arc::new(Wrapping(3))),
    Arc::new(3)
);
assert_eq!(
    ManuallyDrop::into_inner_arc(Arc::new(ManuallyDrop::new(5))),
    Arc::new(5)
);
 
// Calling this as a method requires the "rust_1_46" feature
assert_eq!(Arc::new(Wrapping(3)).into_inner_arc(), Arc::new(3));
assert_eq!(Arc::new(ManuallyDrop::new(5)).into_inner_arc(), Arc::new(5));
 
Available on crate feature alloc only.

Converts self to a Rc<Self::Inner> without allocating.

Self parameter

Enabling the “rust_1_46” feature changes this method from taking a this parameter to taking a self parameter, which allows calling it with .into_inner_rc()

Example
use core_extensions::TransparentNewtypeExt;
 
use std::num::Wrapping;
use std::mem::ManuallyDrop;
use std::rc::Rc;
 
assert_eq!(
    Wrapping::into_inner_rc(Rc::new(Wrapping(3))),
    Rc::new(3)
);
assert_eq!(
    ManuallyDrop::into_inner_rc(Rc::new(ManuallyDrop::new(5))),
    Rc::new(5)
);
 
// Calling this as a method requires the "rust_1_46" feature
assert_eq!(Rc::new(Wrapping(3)).into_inner_rc(), Rc::new(3));
assert_eq!(Rc::new(ManuallyDrop::new(5)).into_inner_rc(), Rc::new(5));
 

Implementors