[][src]Type Definition structural::field_traits::GetFieldType

type GetFieldType<This, FieldName> = <This as GetField<FieldName>>::Ty;

Queries the type of a field.

Example

Here is one way you can get the type of a field.

use structural::{GetField,GetFieldExt,GetFieldType,TI,ti};

fn get_name<T>(this:&T)->&GetFieldType<T,TI!(n a m e)>
where
    T:GetField<TI!(n a m e)>
{
    this.field_(ti!(name))
}


#[derive(structural::Structural)]
struct Huh<T>{
    #[struc(public)]
    #[struc(rename="name")]
    value:T,
}

fn main(){
    let this=Huh{ value:"ooh".to_string() };
     
    assert_eq!( get_name(&this), "ooh" );
}

Another way get_name could have been written is like this:

use structural::{GetField,GetFieldExt,GetFieldType,TI,ti};

fn get_name<T,O>(this:&T)->&O
where
    T:GetField<TI!(n a m e), Ty=O>
{
    this.field_(ti!(name))
}

A potential downside of adding another type parameter is that it makes it less ergonomic to specify the type of T while ignoring the field type, since one has to write it as get_name::<Foo,_>(&foo).