pub trait Wrapper {
type Inner: Clone;
fn from_inner(inner: Self::Inner) -> Self;
fn as_inner(&self) -> &Self::Inner;
fn as_inner_mut(&mut self) -> &mut Self::Inner;
fn into_inner(self) -> Self::Inner;
fn to_inner(&self) -> Self::Inner { ... }
fn copy(&self) -> Self
where
Self: Sized,
Self::Inner: Copy,
{ ... }
}
Expand description
Trait defining wrapped types (“newtypes” in rust terminology). Wrapped types are used for allowing implemeting foreign traits to foreign types: https://doc.rust-lang.org/stable/rust-by-example/generics/new_types.html
Trait defines convenient methods for accessing inner data, construct and deconstruct newtype. It also serves as a marker trait for newtypes.
The trait works well with #[derive(Wrapper)]
from amplify_derive
crate
Required Associated Types
Required Methods
fn from_inner(inner: Self::Inner) -> Self
fn from_inner(inner: Self::Inner) -> Self
Instantiates wrapper type with the inner data
Returns reference to the inner representation for the wrapper type
fn as_inner_mut(&mut self) -> &mut Self::Inner
fn as_inner_mut(&mut self) -> &mut Self::Inner
Returns a mutable reference to the inner representation for the wrapper type
fn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
Unwraps the wrapper returning the inner type