pub struct TypedValue<P: Property> { /* private fields */ }
Expand description
Value object with constraints by Property trait.
Implementations§
Source§impl<P: Property> TypedValue<P>
impl<P: Property> TypedValue<P>
Sourcepub fn new(value: P::Value) -> Result<Self, P::Error>
pub fn new(value: P::Value) -> Result<Self, P::Error>
Method to instantiate a TypedValue.
§Examples
use typed_value::*;
struct MaximumLengthProperty<T, const N:usize>(T);
impl<T: AsRef<str>, const N:usize> Property for MaximumLengthProperty<T, N> {
type Value = T;
type Error = String;
fn validate(value: &Self::Value) -> Result<(), Self::Error> {
if value.as_ref().chars().count() <= N {
Ok(())
} else {
Err(format!("length of \"{}\" is over {}.", value.as_ref(), N))
}
}
}
type MaximumLengthString<const N:usize> = TypedValue<MaximumLengthProperty<String, N>>;
assert!(MaximumLengthString::<5>::new("foobar".to_owned()).is_err());
Trait Implementations§
Source§impl<P: Property> Deref for TypedValue<P>
impl<P: Property> Deref for TypedValue<P>
Source§impl<P: Property<Value = V>, V: Ord> Ord for TypedValue<P>
impl<P: Property<Value = V>, V: Ord> Ord for TypedValue<P>
Source§impl<P: Property<Value = V>, V: PartialOrd> PartialOrd for TypedValue<P>
impl<P: Property<Value = V>, V: PartialOrd> PartialOrd for TypedValue<P>
impl<P: Property<Value = V>, V: Copy> Copy for TypedValue<P>
impl<P: Property<Value = V>, V: Eq> Eq for TypedValue<P>
Auto Trait Implementations§
impl<P> Freeze for TypedValue<P>
impl<P> RefUnwindSafe for TypedValue<P>
impl<P> Send for TypedValue<P>
impl<P> Sync for TypedValue<P>
impl<P> Unpin for TypedValue<P>
impl<P> UnwindSafe for TypedValue<P>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more