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
Required Associated Types
Required Associated Constants
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
.
Replace inner value with the provided one.
It will return an error if the provided value
doesn’t pass
Self::PROCESS
.
fn into_inner(self) -> Self::Inner
fn into_inner(self) -> Self::Inner
Unwrap the value into the inner type.
fn 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
.
fn 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
.
fn 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
.
fn verify(self) -> Result<Self, VerificationError<Self>>
fn verify(self) -> Result<Self, VerificationError<Self>>
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.