Trait new_type_derive::NewTypeRef[][src]

pub trait NewTypeRef {
    type Owned: AsRef<Self>;
    type InnerRef: ?Sized;
    type ValidationError;
    fn to_owned(&self) -> Self::Owned;

    fn validate(value: &Self::InnerRef) -> Result<(), Self::ValidationError> { ... }
}

A trait that provides necessary operations for creating a new type with reference type that can round-trip between the two types and the original wrapped value.

Associated Types

The owned type, must be able to take Self as a reference.

The type of the inner value for the reference type, e.g. str or [u8].

Currently only str is supported.

The error type that is returned in the event validation fails.

Required Methods

Convert the reference into an owned value.

The implementation of this must not fail in order for valid values to round-trip between the owned and reference wrappers.

Provided Methods

Validate the value before allowing it to be wrapped in the new type.

Implementors