Trait type_eq::Has[][src]

pub trait Has<Prop> {
    type Val: Sized;
    fn get<P>(&self) -> Self::Val
    where
        Constrain: TypeEq<Prop, P>
; }

Type-level properties. This trait can be used to associate marker types with properties of the implementating type.

Examples

use type_eq::{Constrain, Has, TypeEq};
 
// marler type for the "name" property
struct Name;
 
struct Foo;
 
impl Has<Name> for Foo {
    type Val = &'static str;
    fn get<P>(&self) -> Self::Val 
    where
        Constrain: TypeEq<Name, P>,
    {
        "Foo"
    }
}
 
assert_eq!("Foo", Foo.get::<Name>());
 

Associated Types

Required Methods

Implementors