Trait Microtype

Source
pub trait Microtype {
    type Inner;

    // Required methods
    fn new(inner: Self::Inner) -> Self;
    fn into_inner(self) -> Self::Inner;
    fn inner(&self) -> &Self::Inner;
    fn inner_mut(&mut self) -> &mut Self::Inner;
    fn convert<T: Microtype<Inner = Self::Inner>>(self) -> T;
}
Expand description

A trait implemented by microtypes

Provides some useful common functions for working with microtypes

Required Associated Types§

Source

type Inner

The type of the wrapped value

For example, the inner type of an EmailAddress could be a String

Required Methods§

Source

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

Create a microtype from the inner value

Source

fn into_inner(self) -> Self::Inner

Consume this microtype and return the value it contains

Source

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

Get a shared reference to the inner value

Source

fn inner_mut(&mut self) -> &mut Self::Inner

Get a mutable reference to the inner value

Source

fn convert<T: Microtype<Inner = Self::Inner>>(self) -> T

Explicitly convert from one microtype to another.

This exists as an alternative to From/Into implementations between different microtypes to make conversions explicit

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§