pub trait Wrapper: Sized {
type Inner;
type Error;
const NAME: &'static str;
const PROCESS: fn(&mut Self::Inner) -> Result<(), Self::Error>;
// Required methods
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>>;
// Provided method
fn mutate(
&mut self,
f: impl FnOnce(&mut Self::Inner),
) -> Result<(), MutationError<Self>>
where Self::Inner: Clone { ... }
}Expand description
Required Associated Constants§
Sourceconst PROCESS: fn(&mut Self::Inner) -> Result<(), Self::Error>
const PROCESS: fn(&mut Self::Inner) -> Result<(), Self::Error>
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 Associated Types§
Required Methods§
Sourcefn new(value: impl Into<Self::Inner>) -> Result<Self, ConstructionError<Self>>
fn new(value: impl Into<Self::Inner>) -> Result<Self, ConstructionError<Self>>
Construct a new wrapper.
It will return an error if the provided value doesn’t pass
Self::PROCESS.
Sourcefn set(
&mut self,
value: impl Into<Self::Inner>,
) -> Result<(), ConstructionError<Self>>
fn set( &mut self, value: impl Into<Self::Inner>, ) -> Result<(), ConstructionError<Self>>
Replace inner value with the provided one.
It will return an error if the provided value doesn’t pass
Self::PROCESS.
Sourcefn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
Unwrap the value into the inner type.
Sourcefn new_unprocessed(value: impl Into<Self::Inner>) -> Self
fn new_unprocessed(value: impl Into<Self::Inner>) -> Self
Construct a new wrapper without calling
Self::PROCESS.
Sourcefn set_unprocessed(&mut self, value: impl Into<Self::Inner>)
fn set_unprocessed(&mut self, value: impl Into<Self::Inner>)
Replace inner value with the provided one without calling
Self::PROCESS.
Sourcefn mutate_unprocessed(&mut self, f: impl FnOnce(&mut Self::Inner))
fn mutate_unprocessed(&mut self, f: impl FnOnce(&mut Self::Inner))
Mutate inner value using provided closure without calling
Self::PROCESS.
Sourcefn verify(self) -> Result<Self, VerificationError<Self>>
fn verify(self) -> Result<Self, VerificationError<Self>>
Verify that inner value still passes Self::PROCESS.
Provided Methods§
Sourcefn mutate(
&mut self,
f: impl FnOnce(&mut Self::Inner),
) -> Result<(), MutationError<Self>>
fn mutate( &mut self, f: impl FnOnce(&mut Self::Inner), ) -> Result<(), MutationError<Self>>
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.
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.