cgp-tests 0.5.0-beta3

Context-generic programming meta crate
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use cgp::prelude::*;

#[derive(HasField)]
pub struct Context(pub String, pub u64);

pub trait CheckHasFieldImpls:
    HasField<Index<0>, Value = String> + HasField<Index<1>, Value = u64>
{
}

impl CheckHasFieldImpls for Context {}

#[test]
fn test_has_field_index() {
    let context = Context("test".to_owned(), 1);
    assert_eq!(context.get_field(PhantomData::<Index<0>>), &"test");
    assert_eq!(context.get_field(PhantomData::<Index<1>>), &1);
}