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 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
Associated Types
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 new_unprocessed(value: impl Into<Self::Inner>) -> Self
fn new_unprocessed(value: impl Into<Self::Inner>) -> Self
unprocessed
only.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>)
unprocessed
only.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))
unprocessed
only.Mutate inner value using provided closure without calling
Self::PROCESS
.
fn verify(self) -> Result<Self, VerificationError<Self>>
fn verify(self) -> Result<Self, VerificationError<Self>>
unprocessed
only.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.