@@ -95,6 +95,21 @@ macro_rules! deref(
95
95
}
96
96
) ;
97
97
98
+ macro_rules! tm {
99
+ ( $id: ident, $tm: ident{ $( $tf: item) * } ) => {
100
+ #[ allow( unused_imports) ]
101
+ mod $tm{
102
+ use std:: str ;
103
+ use $crate:: header:: * ;
104
+ use $crate:: mime:: * ;
105
+ use $crate:: method:: Method ;
106
+ use super :: $id as HeaderField ;
107
+ $( $tf) *
108
+ }
109
+
110
+ }
111
+ }
112
+
98
113
#[ macro_export]
99
114
macro_rules! test_header {
100
115
( $id: ident, $raw: expr) => {
@@ -135,7 +150,7 @@ macro_rules! header {
135
150
// $nn:expr: Nice name of the header
136
151
137
152
// List header, zero or more items
138
- ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) * $tm : ident { $ ( $tf : item ) * } ) => {
153
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) * ) => {
139
154
$( #[ $a] ) *
140
155
#[ derive( Clone , Debug , PartialEq ) ]
141
156
pub struct $id( pub Vec <$item>) ;
@@ -159,19 +174,9 @@ macro_rules! header {
159
174
self . fmt_header( f)
160
175
}
161
176
}
162
- #[ allow( unused_imports) ]
163
- mod $tm{
164
- use std:: str ;
165
- use $crate:: header:: * ;
166
- use $crate:: mime:: * ;
167
- use $crate:: method:: Method ;
168
- use super :: $id as HeaderField ;
169
- $( $tf) *
170
- }
171
-
172
177
} ;
173
178
// List header, one or more items
174
- ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) + $tm : ident { $ ( $tf : item ) * } ) => {
179
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) +) => {
175
180
$( #[ $a] ) *
176
181
#[ derive( Clone , Debug , PartialEq ) ]
177
182
pub struct $id( pub Vec <$item>) ;
@@ -195,18 +200,9 @@ macro_rules! header {
195
200
self . fmt_header( f)
196
201
}
197
202
}
198
- #[ allow( unused_imports) ]
199
- mod $tm{
200
- use std:: str ;
201
- use $crate:: header:: * ;
202
- use $crate:: mime:: * ;
203
- use $crate:: method:: Method ;
204
- use super :: $id as HeaderField ;
205
- $( $tf) *
206
- }
207
203
} ;
208
204
// Single value header
209
- ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => [ $value: ty] $tm : ident { $ ( $tf : item ) * } ) => {
205
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => [ $value: ty] ) => {
210
206
$( #[ $a] ) *
211
207
#[ derive( Clone , Debug , PartialEq ) ]
212
208
pub struct $id( pub $value) ;
@@ -229,18 +225,9 @@ macro_rules! header {
229
225
:: std:: fmt:: Display :: fmt( & * * self , f)
230
226
}
231
227
}
232
- #[ allow( unused_imports) ]
233
- mod $tm{
234
- use std:: str ;
235
- use $crate:: header:: * ;
236
- use $crate:: mime:: * ;
237
- use $crate:: method:: Method ;
238
- use super :: $id as HeaderField ;
239
- $( $tf) *
240
- }
241
228
} ;
242
229
// List header, one or more items with "*" option
243
- ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => { Any / ( $item: ty) +} $tm : ident { $ ( $tf : item ) * } ) => {
230
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => { Any / ( $item: ty) +} ) => {
244
231
$( #[ $a] ) *
245
232
#[ derive( Clone , Debug , PartialEq ) ]
246
233
pub enum $id {
@@ -279,18 +266,44 @@ macro_rules! header {
279
266
self . fmt_header( f)
280
267
}
281
268
}
282
- #[ allow( unused_imports) ]
283
- mod $tm{
284
- use std:: str ;
285
- use $crate:: header:: * ;
286
- use $crate:: mime:: * ;
287
- use $crate:: method:: Method ;
288
- use super :: $id as HeaderField ;
289
- $( $tf) *
269
+ } ;
270
+
271
+ // optional test module
272
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) * $tm: ident{ $( $tf: item) * } ) => {
273
+ header! {
274
+ $( #[ $a] ) *
275
+ ( $id, $n) => ( $item) *
290
276
}
277
+
278
+ tm! { $id, $tm { $( $tf) * } }
279
+ } ;
280
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => ( $item: ty) + $tm: ident{ $( $tf: item) * } ) => {
281
+ header! {
282
+ $( #[ $a] ) *
283
+ ( $id, $n) => ( $item) +
284
+ }
285
+
286
+ tm! { $id, $tm { $( $tf) * } }
287
+ } ;
288
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => [ $item: ty] $tm: ident{ $( $tf: item) * } ) => {
289
+ header! {
290
+ $( #[ $a] ) *
291
+ ( $id, $n) => [ $item]
292
+ }
293
+
294
+ tm! { $id, $tm { $( $tf) * } }
295
+ } ;
296
+ ( $( #[ $a: meta] ) * ( $id: ident, $n: expr) => { Any / ( $item: ty) +} $tm: ident{ $( $tf: item) * } ) => {
297
+ header! {
298
+ $( #[ $a] ) *
299
+ ( $id, $n) => { Any / ( $item) +}
300
+ }
301
+
302
+ tm! { $id, $tm { $( $tf) * } }
291
303
} ;
292
304
}
293
305
306
+
294
307
mod accept;
295
308
mod access_control_allow_headers;
296
309
mod access_control_allow_methods;
0 commit comments