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
type Owned: AsRef<Self>
The owned type, must be able to take Self
as a reference.
type InnerRef: ?Sized
The type of the inner value for the reference type, e.g. str
or
[u8]
.
Currently only str
is supported.
type ValidationError
The error type that is returned in the event validation fails.
Required Methods
fn to_owned(&self) -> Self::Owned
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
fn validate(value: &Self::InnerRef) -> Result<(), Self::ValidationError>
Validate the value before allowing it to be wrapped in the new type.