Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(header): make test_module of header! optional #492

Merged
merged 1 commit into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/headers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![deny(warnings)]

#[macro_use]
// TODO: only import header!, blocked by https://github.com/rust-lang/rust/issues/25003
extern crate hyper;

// A header in the form of `X-Foo: some random string`
header! {
(Foo, "X-Foo") => [String]
}

fn main() {
}
93 changes: 53 additions & 40 deletions src/header/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ macro_rules! deref(
}
);

macro_rules! tm {
($id:ident, $tm:ident{$($tf:item)*}) => {
#[allow(unused_imports)]
mod $tm{
use std::str;
use $crate::header::*;
use $crate::mime::*;
use $crate::method::Method;
use super::$id as HeaderField;
$($tf)*
}

}
}

#[macro_export]
macro_rules! test_header {
($id:ident, $raw:expr) => {
Expand Down Expand Up @@ -135,7 +150,7 @@ macro_rules! header {
// $nn:expr: Nice name of the header

// List header, zero or more items
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)* $tm:ident{$($tf:item)*}) => {
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)*) => {
$(#[$a])*
#[derive(Clone, Debug, PartialEq)]
pub struct $id(pub Vec<$item>);
Expand All @@ -159,19 +174,9 @@ macro_rules! header {
self.fmt_header(f)
}
}
#[allow(unused_imports)]
mod $tm{
use std::str;
use $crate::header::*;
use $crate::mime::*;
use $crate::method::Method;
use super::$id as HeaderField;
$($tf)*
}

};
// List header, one or more items
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+ $tm:ident{$($tf:item)*}) => {
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+) => {
$(#[$a])*
#[derive(Clone, Debug, PartialEq)]
pub struct $id(pub Vec<$item>);
Expand All @@ -195,18 +200,9 @@ macro_rules! header {
self.fmt_header(f)
}
}
#[allow(unused_imports)]
mod $tm{
use std::str;
use $crate::header::*;
use $crate::mime::*;
use $crate::method::Method;
use super::$id as HeaderField;
$($tf)*
}
};
// Single value header
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty] $tm:ident{$($tf:item)*}) => {
($(#[$a:meta])*($id:ident, $n:expr) => [$value:ty]) => {
$(#[$a])*
#[derive(Clone, Debug, PartialEq)]
pub struct $id(pub $value);
Expand All @@ -229,18 +225,9 @@ macro_rules! header {
::std::fmt::Display::fmt(&**self, f)
}
}
#[allow(unused_imports)]
mod $tm{
use std::str;
use $crate::header::*;
use $crate::mime::*;
use $crate::method::Method;
use super::$id as HeaderField;
$($tf)*
}
};
// List header, one or more items with "*" option
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+}) => {
$(#[$a])*
#[derive(Clone, Debug, PartialEq)]
pub enum $id {
Expand Down Expand Up @@ -279,18 +266,44 @@ macro_rules! header {
self.fmt_header(f)
}
}
#[allow(unused_imports)]
mod $tm{
use std::str;
use $crate::header::*;
use $crate::mime::*;
use $crate::method::Method;
use super::$id as HeaderField;
$($tf)*
};

// optional test module
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)* $tm:ident{$($tf:item)*}) => {
header! {
$(#[$a])*
($id, $n) => ($item)*
}

tm! { $id, $tm { $($tf)* }}
};
($(#[$a:meta])*($id:ident, $n:expr) => ($item:ty)+ $tm:ident{$($tf:item)*}) => {
header! {
$(#[$a])*
($id, $n) => ($item)+
}

tm! { $id, $tm { $($tf)* }}
};
($(#[$a:meta])*($id:ident, $n:expr) => [$item:ty] $tm:ident{$($tf:item)*}) => {
header! {
$(#[$a])*
($id, $n) => [$item]
}

tm! { $id, $tm { $($tf)* }}
};
($(#[$a:meta])*($id:ident, $n:expr) => {Any / ($item:ty)+} $tm:ident{$($tf:item)*}) => {
header! {
$(#[$a])*
($id, $n) => {Any / ($item)+}
}

tm! { $id, $tm { $($tf)* }}
};
}


mod accept;
mod access_control_allow_headers;
mod access_control_allow_methods;
Expand Down