#[macro_use]
mod macros;
#[derive(serde::Serialize)]
struct BorrowedNameWrapper<'a>(#[serde(with = "crate::header_name")] &'a http::HeaderName);
#[derive(serde::Deserialize)]
struct NameWrapper(#[serde(with = "crate::header_name")] http::HeaderName);
#[derive(serde::Deserialize)]
#[serde(untagged)]
enum Either<T> {
One(T),
Many(Vec<T>),
}
#[inline]
fn insert_header_values<'a, M, T>(
map: &mut http::HeaderMap<T>,
key: http::HeaderName,
mut values: impl Iterator<Item = T>,
) -> Result<(), M::Error>
where
M: serde::de::MapAccess<'a>,
{
if let http::header::Entry::Vacant(e) = map.entry(key) {
if let Some(first) = values.next() {
let mut e = e.insert_entry(first);
for val in values {
e.append(val);
}
} else {
return Err(serde::de::Error::custom(format!(
"no value for header {}",
e.key()
)));
}
}
Ok(())
}
macro_rules! doc_mod {
{ $ty:ty, $path:ident$(, $generic:ident)? } => {
#[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::", stringify!($ty), "`]")]
#[doc = concat!("use http::", stringify!($ty), ";")]
#[doc = concat!("struct MyStruct<T", $(", ", stringify!($generic), )?">")]
$(#[doc = concat!(" ", stringify!($generic), ": Serialize + for<'a> Deserialize<'a>,") ])?
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "\")]")]
#[doc = concat!(" base: ", stringify!($ty), $("<", stringify!($generic), ">",)? ",")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::option\", default)]")]
#[doc = concat!(" option: Option<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::result\")]")]
#[doc = concat!(" result: Result<", stringify!($ty), $("<", stringify!($generic), ">",)? ", T>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec\")]")]
#[doc = concat!(" vec: Vec<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec_deque\")]")]
#[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::linked_list\")]")]
#[doc = concat!(" linked_list: LinkedList<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_map\")]")]
#[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::btree_map\")]")]
#[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
pub mod $path;
}
}
macro_rules! doc_mod_hash {
($ty:ty, $path:ident$(, $extra:expr)?) => {
#[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::"$(, $extra)?, stringify!($ty), "`]")]
#[doc = concat!("use http::", $($extra,)? stringify!($ty), ";")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "\")]")]
#[doc = concat!(" base: ", stringify!($ty), ",")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::option\", default)]")]
#[doc = concat!(" option: Option<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::result\")]")]
#[doc = concat!(" result: Result<", stringify!($ty), ", U>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec\")]")]
#[doc = concat!(" vec: Vec<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec_deque\")]")]
#[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::linked_list\")]")]
#[doc = concat!(" linked_list: LinkedList<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_map\")]")]
#[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_map_key\")]")]
#[doc = concat!(" hash_map_key: HashMap<", stringify!($ty), ", U>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::btree_map\")]")]
#[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_set\")]")]
#[doc = concat!(" hash_set: HashSet<", stringify!($ty), ">,")]
pub mod $path;
};
}
macro_rules! doc_mod_ord_and_hash {
($ty:ty, $path:ident) => {
#[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::", stringify!($ty), "`]")]
#[doc = concat!("use http::", stringify!($ty), ";")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "\")]")]
#[doc = concat!(" base: ", stringify!($ty), ",")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::option\", default)]")]
#[doc = concat!(" option: Option<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::result\")]")]
#[doc = concat!(" result: Result<", stringify!($ty), ", U>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec\")]")]
#[doc = concat!(" vec: Vec<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::vec_deque\")]")]
#[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::linked_list\")]")]
#[doc = concat!(" linked_list: LinkedList<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_map\")]")]
#[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_map_key\")]")]
#[doc = concat!(" hash_map_key: HashMap<", stringify!($ty), ", U>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::btree_map\")]")]
#[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::btree_map_key\")]")]
#[doc = concat!(" btree_map_key: BTreeMap<", stringify!($ty), ", U>,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::hash_set\")]")]
#[doc = concat!(" hash_set: HashSet<", stringify!($ty), ">,")]
#[doc = concat!(" #[serde(with = \"http_serde_ext::", stringify!($path), "::btree_set\")]")]
#[doc = concat!(" btree_set: BTreeSet<", stringify!($ty), ">,")]
pub mod $path;
};
}
doc_mod_hash!(Authority, authority, "uri::");
doc_mod!(HeaderMap, header_map);
doc_mod!(HeaderMap, header_map_generic, U);
doc_mod_hash!(HeaderName, header_name);
doc_mod_ord_and_hash!(HeaderValue, header_value);
doc_mod_hash!(Method, method);
doc_mod_hash!(PathAndQuery, path_and_query, "uri::");
doc_mod!(Request, request, U);
doc_mod!(Response, response, U);
doc_mod_hash!(Scheme, scheme, "uri::");
doc_mod_ord_and_hash!(StatusCode, status_code);
doc_mod_hash!(Uri, uri);
doc_mod_ord_and_hash!(Version, version);