Trait amplify::Wrapper

source ·
pub trait Wrapper {
    type Inner;

    // Required methods
    fn from_inner(inner: Self::Inner) -> Self;
    fn as_inner(&self) -> &Self::Inner;
    fn into_inner(self) -> Self::Inner;

    // Provided methods
    fn to_inner(&self) -> Self::Inner
       where Self::Inner: Clone { ... }
    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§

source

type Inner

Inner type wrapped by the current newtype

Required Methods§

source

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

Instantiates wrapper type with the inner data

source

fn as_inner(&self) -> &Self::Inner

Returns reference to the inner representation for the wrapper type

source

fn into_inner(self) -> Self::Inner

Unwraps the wrapper returning the inner type

Provided Methods§

source

fn to_inner(&self) -> Self::Inner
where Self::Inner: Clone,

Clones inner data of the wrapped type and return them

source

fn copy(&self) -> Self
where Self: Sized, Self::Inner: Copy,

Copies the wrapped type

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C: Collection, const MIN_LEN: usize, const MAX_LEN: usize> Wrapper for Confined<C, MIN_LEN, MAX_LEN>

§

type Inner = C

source§

impl<T, const LEN: usize, const REVERSE_STR: bool> Wrapper for Array<T, LEN, REVERSE_STR>