snowboard 0.9.0

fast, simple & reliable http servers 🏂
Documentation
//! A module that handles and provides easy to use macros for the user.

/// A quick way to create responses.
///
/// Usage:
/// ```
/// use snowboard::{response, headers};
/// use std::collections::HashMap;
///
/// // Response with no headers and no body.
/// let response = response!(bad_request);
///
/// // Response with body and no headers.
/// // Note that $body requires to implement `Into<Vec<u8>>`.
/// let res =  response!(internal_server_error, "oopsies");
///
/// // Response with body and headers.
/// let body = "everything's fine!";
/// let headers = headers! {
///     "Content-Type" => "text/html",
///     "X-Hello" => "World!",
///     "X-Number" => 42,
/// };
/// let alright = response!(ok, body, headers);
/// ```
///
/// See [headers!](crate::headers) for more information about the headers macro.
#[macro_export]
macro_rules! response {
	(ok) => {
		$crate::Response::default()
	};

	(continue $(, $($rest:expr_2021),* )?) => {
		$crate::response!(continue_ $(, $($rest),* )?)
	};

	($type:ident) => {
		$crate::Response::$type(vec![], $crate::Headers::default(), $crate::_DEFAULT_HTTP_VERSION)
	};

	($type:ident,$body:expr_2021) => {
		$crate::Response::$type($body.into(), $crate::Headers::default(), $crate::_DEFAULT_HTTP_VERSION)
	};

	($type:ident,$body:expr_2021,$headers:expr_2021) => {
		$crate::Response::$type($body.into(), $headers, $crate::_DEFAULT_HTTP_VERSION)
	};
}

/// A quick way to create a header HashMap.
///
/// A similar version of this macro can be found in other
/// crates as `map!` or `hashmap!`.
///
/// This will convert any `$value` to a String, since
/// the headers are stored as `HashMap<&str, String>`.
///
/// Example:
/// ```rust
/// use snowboard::headers;
///
/// let headers = headers! {
///     "Content-Type" => "text/html",
///     "X-Hello" => "World!",
///     "X-Number" => 42,
/// };
/// ```
#[macro_export]
macro_rules! headers {
	($($name:expr_2021 => $value:expr_2021 $(,)?)*) => {{
		let mut map = ::std::collections::HashMap::<&str, String>::new();
		$(map.insert($name, $value.to_string());)*
		map
	}};
}