newtype_tools/lib.rs
1#![doc = include_str!("../README.md")]
2
3#[cfg(feature = "derive")]
4pub use newtype_tools_derive::Newtype;
5
6/// `Newtype` trait defines conversions from and into the inner type.
7///
8/// This trait is automatically derived for all types annotated with
9/// `#[derive(Newtype)]`.
10pub trait Newtype {
11 /// The inner type.
12 type Inner;
13
14 /// Creates a new `newtype` instance from the inner representation.
15 fn new(inner: Self::Inner) -> Self;
16
17 /// Unwraps the value, consuming the `newtype`.
18 fn into_inner(self) -> Self::Inner;
19}