diff options
Diffstat (limited to 'mail/src/macros.rs')
-rw-r--r-- | mail/src/macros.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/mail/src/macros.rs b/mail/src/macros.rs new file mode 100644 index 0000000..0603ebc --- /dev/null +++ b/mail/src/macros.rs @@ -0,0 +1,33 @@ +//FIXE[rustc/macro reexport] re-export the macro once possible in stable +// currently this won't work well so this is just a copy of the macro in +// mail-headers ;=( +/// Create a header map from a list of header's with ther fields +/// +/// # Example +/// +/// ``` +/// # #[macro_use] +/// # extern crate mail_headers; +/// # use mail_headers::headers::*; +/// # use mail_headers::error::ComponentCreationError; +/// # fn main() { (|| -> Result<(), ComponentCreationError> { +/// let map = headers! { +/// _From: ["bobo@nana.test"], +/// Subject: "hy there" +/// }?; +/// # Ok(()) })(); } +/// ``` +#[macro_export] +macro_rules! headers { + ($($header:ty : $val:expr),*) => ({ + //FIXME[rust/catch block] use catch block once available + (|| -> Result<$crate::HeaderMap, ::mail::error::ComponentCreationError> + { + let mut map = ::mail::HeaderMap::new(); + $( + map.insert(<$header as ::mail::HeaderKind>::body($val)?); + )* + Ok(map) + })() + }); +}
\ No newline at end of file |