[][src]Macro structural::ti

macro_rules! ti {
    ( $($strings:tt),* ) => { ... };
}

Constructs field identifier(s) (TString/TStringSet).

The arguments to this macro can be either identifiers or string literals.

This macro doesn't take aliases for field identifiers, they must be the literal name of the fields.

When passed a single argument,this instantiates a TString, which is what's passed to the GetFieldExt::{field_,field_mut,into_field,box_into_field} methods.

When passed multiple arguments,this instantiates a TStringSet which is what's passed to the GetFieldExt::{fields,fields_mut} methods. This requires unique arguments to be passed, otherwise this macro will cause a compile-time error.

Example

use structural::{GetFieldExt,ti};

{
    let tup=("I","you","they");
    
    assert_eq!( tup.field_(ti!(0)), &"I" );
    assert_eq!( tup.field_(ti!(1)), &"you" );
    assert_eq!( tup.field_(ti!(2)), &"they" );
    
    assert_eq!( tup.fields(ti!(0,1)), (&"I",&"you") );
    
    assert_eq!( tup.fields(ti!(0,1,2)), (&"I",&"you",&"they") );
}

#[derive(structural::Structural)]
#[struc(public)]
#[struc(access="mut move")]
struct Foo{
    bar:u32,
    baz:u32,
    ooo:u32,
}

{
    let mut foo=Foo{
        bar:0,
        baz:44,
        ooo:66,
    };
     
    assert_eq!( foo.field_(ti!(bar)), &0 );
    assert_eq!( foo.field_(ti!(baz)), &44 );
    assert_eq!( foo.field_(ti!(ooo)), &66 );

    assert_eq!( foo.fields(ti!(ooo,bar)), (&66,&0) );
    assert_eq!( foo.fields(ti!(bar,ooo,baz)), (&0,&66,&44) );

    assert_eq!( foo.fields_mut(ti!(ooo,bar)), (&mut 66, &mut 0) );
    assert_eq!( foo.fields_mut(ti!(bar,ooo,baz)), (&mut 0, &mut 66, &mut 44) );
         
}

Example

You can't pass multiple identical arguments to this macro,as this demonstrates:

This example deliberately fails to compile
use structural::ti;

let _=ti!(hello,hello);