Trait TypedValueExt

Source
pub trait TypedValueExt: Sized {
    // Required method
    fn typed<P: Property<Value = Self>>(self) -> Result<TypedValue<P>, P::Error>;
}
Expand description

Trait that provides a wrapping method to TypedValue for any value.

Required Methods§

Source

fn typed<P: Property<Value = Self>>(self) -> Result<TypedValue<P>, P::Error>

§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>>;

let foobar = "foobar".to_owned();
let _: MaximumLengthString<6> = foobar.typed().unwrap();

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.

Implementors§

Source§

impl<T> TypedValueExt for T