tt_call/
predicate.rs

1/// Predicate that is always true.
2/// <sup>**[tt-call]**</sup>
3///
4/// # Input
5///
6///   - `input = [{` anything `}]`
7///
8/// # Output
9///
10///   - `output = [{ true }]`
11#[macro_export]
12macro_rules! tt_true {
13    {
14        $caller:tt
15        input = [{ $($in:tt)* }]
16    } => {
17        $crate::tt_return! {
18            $caller
19            output = [{ true }]
20        }
21    }
22}
23
24/// Predicate that is always false.
25/// <sup>**[tt-call]**</sup>
26///
27/// # Input
28///
29///   - `input = [{` anything `}]`
30///
31/// # Output
32///
33///   - `output = [{ false }]`
34#[macro_export]
35macro_rules! tt_false {
36    {
37        $caller:tt
38        input = [{ $($in:tt)* }]
39    } => {
40        $crate::tt_return! {
41            $caller
42            output = [{ false }]
43        }
44    }
45}
46
47/// Predicate that accepts a single token and determines whether it is a comma.
48/// <sup>**[tt-call]**</sup>
49///
50/// # Input
51///
52///   - `input = [{` a single token tree `}]`
53///
54/// # Output
55///
56///   - `is_comma = [{` either true or false `}]`
57#[macro_export]
58macro_rules! tt_is_comma {
59    {
60        $caller:tt
61        input = [{ , }]
62    } => {
63        $crate::tt_return! {
64            $caller
65            is_comma = [{ true }]
66        }
67    };
68
69    {
70        $caller:tt
71        input = [{ $other:tt }]
72    } => {
73        $crate::tt_return! {
74            $caller
75            is_comma = [{ false }]
76        }
77    };
78}
79
80/// Predicate that accepts a single token and determines whether it is an
81/// identifier.
82/// <sup>**[tt-call]**</sup>
83///
84/// An identifier is anything that matches Rust's `$:ident` fragment.
85///
86/// # Input
87///
88///   - `input = [{` a single token tree `}]`
89///
90/// # Output
91///
92///   - `is_ident = [{` either true or false `}]`
93#[macro_export]
94macro_rules! tt_is_ident {
95    {
96        $caller:tt
97        input = [{ $ident:ident }]
98    } => {
99        $crate::tt_return! {
100            $caller
101            is_ident = [{ true }]
102        }
103    };
104
105    {
106        $caller:tt
107        input = [{ $other:tt }]
108    } => {
109        $crate::tt_return! {
110            $caller
111            is_ident = [{ false }]
112        }
113    };
114}
115
116/// Predicate that accepts a single token and determines whether it is a
117/// lifetime token.
118/// <sup>**[tt-call]**</sup>
119///
120/// # Input
121///
122///   - `input = [{` a single token tree `}]`
123///
124/// # Output
125///
126///   - `is_lifetime = [{` either true or false `}]`
127#[macro_export]
128macro_rules! tt_is_lifetime {
129    {
130        $caller:tt
131        input = [{ $lifetime:lifetime }]
132    } => {
133        $crate::tt_return! {
134            $caller
135            is_lifetime = [{ true }]
136        }
137    };
138
139    {
140        $caller:tt
141        input = [{ $other:tt }]
142    } => {
143        $crate::tt_return! {
144            $caller
145            is_lifetime = [{ false }]
146        }
147    };
148}