@@ -95,6 +95,21 @@ macro_rules! deref(
9595 }
9696) ;
9797
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+
98113#[ macro_export]
99114macro_rules! test_header {
100115 ( $id: ident, $raw: expr) => {
@@ -135,7 +150,7 @@ macro_rules! header {
135150 // $nn:expr: Nice name of the header
136151
137152 // 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) * ) => {
139154 $( #[ $a] ) *
140155 #[ derive( Clone , Debug , PartialEq ) ]
141156 pub struct $id( pub Vec <$item>) ;
@@ -159,19 +174,9 @@ macro_rules! header {
159174 self . fmt_header( f)
160175 }
161176 }
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-
172177 } ;
173178 // 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) +) => {
175180 $( #[ $a] ) *
176181 #[ derive( Clone , Debug , PartialEq ) ]
177182 pub struct $id( pub Vec <$item>) ;
@@ -195,18 +200,9 @@ macro_rules! header {
195200 self . fmt_header( f)
196201 }
197202 }
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- }
207203 } ;
208204 // 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] ) => {
210206 $( #[ $a] ) *
211207 #[ derive( Clone , Debug , PartialEq ) ]
212208 pub struct $id( pub $value) ;
@@ -229,18 +225,9 @@ macro_rules! header {
229225 :: std:: fmt:: Display :: fmt( & * * self , f)
230226 }
231227 }
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- }
241228 } ;
242229 // 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) +} ) => {
244231 $( #[ $a] ) *
245232 #[ derive( Clone , Debug , PartialEq ) ]
246233 pub enum $id {
@@ -279,18 +266,44 @@ macro_rules! header {
279266 self . fmt_header( f)
280267 }
281268 }
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) *
290276 }
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) * } }
291303 } ;
292304}
293305
306+
294307mod accept;
295308mod access_control_allow_headers;
296309mod access_control_allow_methods;
0 commit comments