Macro tstr::ts

source ·
macro_rules! ts {
    ($($expr:expr),* $(,)* ) => { ... };
}
Expand description

A type-level string TStr value.

§Arguments

You can use anything that the tstr::TS macro accepts

§Examples

§Indexing

This uses types from the for_examples module, which can be seen in the docs with the “for_examples” feature.

use tstr::ts;
use tstr::for_examples::{Foo, Bar};

let this = Foo::new(3, 5, "8");
assert_eq!(this[ts!(bar)], 3);
assert_eq!(this[ts!(baz)], 5);
assert_eq!(this[ts!(qux)], "8");

let other = Bar::new(13, false, Some('C'));
assert_eq!(other[ts!(bar)], 13);
assert_eq!(other[ts!(baz)], false);
assert_eq!(other[ts!(boom)], Some('C'));

§Equivalences

This example demonstrates which invocations of ts produce the same values.

use tstr::ts;

let hello1 = ts!("hello");
let hello2 = ts!(hello); // This is equivalent to `ts!("hello")`

let hundreda = ts!("100");
let hundredb = ts!(100);   // equivalent to `ts!("100")`
let hundredc = ts!(0x64);  // equivalent to `ts!("100")`
let hundredd = ts!(0b1100100);  // equivalent to `ts!("100")`

let tup = ts!(foo, 1, "bar"); // equivalent to `(ts!(foo), ts!(1), ts!(bar))`

// Equivalent to ts!("foo4bar200")
let conc = ts!(concat!(foo, 0b100, "bar", 200));