pub trait Wrapper: Sized {
    type Inner;
    type Error;

    const NAME: &'static str;
    const PROCESS: fn(_: &mut Self::Inner) -> Result<(), Self::Error>;

    fn new(
        value: impl Into<Self::Inner>
    ) -> Result<Self, ConstructionError<Self>>; fn get(&self) -> &Self::Inner; fn set(
        &mut self,
        value: impl Into<Self::Inner>
    ) -> Result<(), ConstructionError<Self>>; fn into_inner(self) -> Self::Inner; fn new_unprocessed(value: impl Into<Self::Inner>) -> Self; fn set_unprocessed(&mut self, value: impl Into<Self::Inner>); fn mutate_unprocessed(&mut self, f: impl FnOnce(&mut Self::Inner)); fn verify(self) -> Result<Self, VerificationError<Self>>; fn mutate(
        &mut self,
        f: impl FnOnce(&mut Self::Inner)
    ) -> Result<(), MutationError<Self>>
    where
        Self::Inner: Clone
, { ... } }
Expand description

A trait that describes a Newtype wrapper struct generated by define! and extend! macros.

Required Associated Types

The inner type of the wrapper.

The type of an error that can occur during the construction or mutation of the wrapper’s value.

Required Associated Constants

Name of the wrapper. Will be used for nice error messages.

The function that will mutate and validate wrapper’s inner value on every construction and mutation.

It’s behaviour is based on the closures that were provided during the invocation of define!/extend! macros (e.g. adjust, ensure and validate).

If no closures were provided, this function will not mutate the value and always return Ok(()).

Required Methods

Construct a new wrapper.

It will return an error if the provided value doesn’t pass Self::PROCESS.

Get a shared reference to the inner value.

Replace inner value with the provided one.

It will return an error if the provided value doesn’t pass Self::PROCESS.

Unwrap the value into the inner type.

Construct a new wrapper without calling Self::PROCESS.

Replace inner value with the provided one without calling Self::PROCESS.

Mutate inner value using provided closure without calling Self::PROCESS.

Verify that inner value still passes Self::PROCESS.

Provided Methods

Mutate inner value using provided closure.

To make sure that the closure doesn’t corrupt the inner value, this method is only available when the inner type implements Clone. This way, the closure receives a copy of the inner value, and then, if the mutated value passes Self::PROCESS, it will replace the inner value.

Implementors