Skip to main content

Newtype

Trait Newtype 

Source
pub trait Newtype {
    type Inner;

    // Required methods
    fn new(inner: Self::Inner) -> Self;
    fn into_inner(self) -> Self::Inner;
}
Expand description

Newtype trait defines conversions from and into the inner type.

This trait is automatically derived for all types annotated with #[derive(Newtype)].

Required Associated Types§

Source

type Inner

The inner type.

Required Methods§

Source

fn new(inner: Self::Inner) -> Self

Creates a new newtype instance from the inner representation.

Source

fn into_inner(self) -> Self::Inner

Unwraps the value, consuming the newtype.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§