[][src]Macro structural::TI

macro_rules! TI {
    ($($char:tt)*) => { ... };
}

Constructs a type-level identifier for use as a generic parameter.

Future Compatibility

This macro will continue supporting space separated characters even after identifiers and string literals are supported

Improved macro

To get an improved version of this macro (it requires Rust nightly or Rust 1.40) which can also take an identifier or string literal parameter, you can use either the nightly_better_ti or better_ti cargo features.

You would use better_ti to make TI!(0)/TI!(hello)/TI!("world") work in Rust from 1.40 onwards (proc-macros in type position is stabilizing on Rust 1.40 on as of 2019-11-02).

You would use nightly_better_ti to to make TI!(0)/TI!(hello)/TI!("world") work in Rust nightly from 1.40 backwards.

Once proc-macros in types reaches stable this will be enabled automatically for Rust versions since.

Examples

This demonstrates how one can bound types by the accessor traits in a where clause.

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

fn greet_entity<This,S>(entity:&This)
where
    This:GetField<TI!(n a m e),Ty=S>,
    S:AsRef<str>,
{
    println!("Hello, {}!",entity.field_(ti!(name)).as_ref() );
}

Example

This demonstrates the improved version of this macro,which requires either the the nightly_better_ti or better_ti cargo features. Once proc-macros in types reaches stable this will be usable automatically for Rust versions since.

This example is not tested
use structural::{GetField,GetFieldExt,ti,TI};

fn greet_entity<This,S>(entity:&This)
where
    This:GetField<TI!(name),Ty=S>,
    S:AsRef<str>,
{
    println!("Hello, {}!",entity.field_(ti!(name)).as_ref() );
}

type NumericIdent=TI!(0);
type StringyIdent=TI!("huh");