1#[macro_use]
86mod macros;
87
88#[derive(serde::Serialize)]
89struct BorrowedNameWrapper<'a>(#[serde(with = "crate::header_name")] &'a http::HeaderName);
90
91#[derive(serde::Deserialize)]
92#[serde(transparent)]
93struct NameWrapper(#[serde(with = "crate::header_name")] http::HeaderName);
94
95#[derive(serde::Deserialize)]
96#[serde(untagged)]
97enum Either<T> {
98 One(T),
99 Many(Vec<T>),
100}
101
102#[inline]
103fn insert_header_values<'a, M, T>(
104 map: &mut http::HeaderMap<T>,
105 key: http::HeaderName,
106 mut values: impl Iterator<Item = T>,
107) -> Result<(), M::Error>
108where
109 M: serde::de::MapAccess<'a>,
110{
111 if let http::header::Entry::Vacant(e) = map.entry(key) {
112 if let Some(first) = values.next() {
113 let mut e = e.insert_entry(first);
114
115 for val in values {
116 e.append(val);
117 }
118 } else {
119 return Err(serde::de::Error::custom(format!(
120 "no value for header {}",
121 e.key()
122 )));
123 }
124 }
125
126 Ok(())
127}
128
129macro_rules! doc_mod {
130 { $ty:ty, $path:ident$(, $generic:ident)? } => {
131 #[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::", stringify!($ty), "`]")]
132 #[doc = concat!("use http::", stringify!($ty), ";")]
137 #[doc = concat!("struct MyStruct<T", $(", ", stringify!($generic), )?">")]
141 $(#[doc = concat!(" ", stringify!($generic), ": Serialize + for<'a> Deserialize<'a>,") ])?
144 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "\")]")]
146 #[doc = concat!(" base: ", stringify!($ty), $("<", stringify!($generic), ">",)? ",")]
147 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::option\", default)]")]
149 #[doc = concat!(" option: Option<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
150 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::result\")]")]
152 #[doc = concat!(" result: Result<", stringify!($ty), $("<", stringify!($generic), ">",)? ", T>,")]
153 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec\")]")]
155 #[doc = concat!(" vec: Vec<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
156 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec_deque\")]")]
158 #[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
159 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::linked_list\")]")]
161 #[doc = concat!(" linked_list: LinkedList<", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
162 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_map\")]")]
164 #[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
165 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::btree_map\")]")]
167 #[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), $("<", stringify!($generic), ">",)? ">,")]
168 pub mod $path;
171 }
172}
173
174macro_rules! doc_mod_hash {
175 ($ty:ty, $path:ident$(, $extra:expr)?) => {
176 #[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::"$(, $extra)?, stringify!($ty), "`]")]
177 #[doc = concat!("use http::", $($extra,)? stringify!($ty), ";")]
182 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "\")]")]
191 #[doc = concat!(" base: ", stringify!($ty), ",")]
192 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::option\", default)]")]
194 #[doc = concat!(" option: Option<", stringify!($ty), ">,")]
195 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::result\")]")]
197 #[doc = concat!(" result: Result<", stringify!($ty), ", U>,")]
198 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec\")]")]
200 #[doc = concat!(" vec: Vec<", stringify!($ty), ">,")]
201 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec_deque\")]")]
203 #[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), ">,")]
204 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::linked_list\")]")]
206 #[doc = concat!(" linked_list: LinkedList<", stringify!($ty), ">,")]
207 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_map\")]")]
209 #[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), ">,")]
210 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_map_key\")]")]
212 #[doc = concat!(" hash_map_key: HashMap<", stringify!($ty), ", U>,")]
213 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::btree_map\")]")]
215 #[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), ">,")]
216 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_set\")]")]
218 #[doc = concat!(" hash_set: HashSet<", stringify!($ty), ">,")]
219 pub mod $path;
222 };
223}
224
225macro_rules! doc_mod_ord_and_hash {
226 ($ty:ty, $path:ident) => {
227 #[doc = concat!(" [`Serialize`](serde::Serialize)/[`Deserialize`](serde::Deserialize) for [`http::", stringify!($ty), "`]")]
228 #[doc = concat!("use http::", stringify!($ty), ";")]
233 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "\")]")]
242 #[doc = concat!(" base: ", stringify!($ty), ",")]
243 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::option\", default)]")]
245 #[doc = concat!(" option: Option<", stringify!($ty), ">,")]
246 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::result\")]")]
248 #[doc = concat!(" result: Result<", stringify!($ty), ", U>,")]
249 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec\")]")]
251 #[doc = concat!(" vec: Vec<", stringify!($ty), ">,")]
252 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::vec_deque\")]")]
254 #[doc = concat!(" vec_deque: VecDeque<", stringify!($ty), ">,")]
255 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::linked_list\")]")]
257 #[doc = concat!(" linked_list: LinkedList<", stringify!($ty), ">,")]
258 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_map\")]")]
260 #[doc = concat!(" hash_map: HashMap<T, ", stringify!($ty), ">,")]
261 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_map_key\")]")]
263 #[doc = concat!(" hash_map_key: HashMap<", stringify!($ty), ", U>,")]
264 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::btree_map\")]")]
266 #[doc = concat!(" btree_map: BTreeMap<T, ", stringify!($ty), ">,")]
267 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::btree_map_key\")]")]
269 #[doc = concat!(" btree_map_key: BTreeMap<", stringify!($ty), ", U>,")]
270 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::hash_set\")]")]
272 #[doc = concat!(" hash_set: HashSet<", stringify!($ty), ">,")]
273 #[doc = concat!(" #[serde(with = \"http_serde_ext_ios::", stringify!($path), "::btree_set\")]")]
275 #[doc = concat!(" btree_set: BTreeSet<", stringify!($ty), ">,")]
276 pub mod $path;
279 };
280}
281
282doc_mod_hash!(Authority, authority, "uri::");
283doc_mod!(HeaderMap, header_map);
284doc_mod!(HeaderMap, header_map_generic, U);
285doc_mod_hash!(HeaderName, header_name);
286doc_mod_ord_and_hash!(HeaderValue, header_value);
287doc_mod_hash!(Method, method);
288doc_mod_hash!(PathAndQuery, path_and_query, "uri::");
289doc_mod!(Request, request, U);
290doc_mod!(Response, response, U);
291doc_mod_hash!(Scheme, scheme, "uri::");
292doc_mod_ord_and_hash!(StatusCode, status_code);
293doc_mod_hash!(Uri, uri);
294doc_mod_ord_and_hash!(Version, version);