Expand description
§serde extensions for the http crate types
Allows serializing and deserializing the following types from http:
RequestResponseHeaderMapStatusCodeUriMethodHeaderNameHeaderValueuri::Authorityuri::Schemeuri::PathAndQueryVersion- Generic
HeaderMap<T>where the item is not aHeaderValue
Allows serializing and deserializing the above types wrapped in the following std container types:
OptionResultin theOkpositionVecVecDequeLinkedListHashMapas theKeyfor all exceptHeaderMap,Request, andResponse. As theValuefor all types.BTreeMapas theKeyonly forHeaderValue,StatusCode, andVersion. As theValuefor all types.HashSetfor all exceptHeaderMap,Request, andResponseBTreeSetonly forHeaderValue,StatusCode, andVersion
§Usage
This library is intended to be used with serde’s derive feature.
Fields should use the appropriate #[serde(with = "...")] annotation for that
type. Full examples are provided in each module section of these docs.
use std::collections::*;
use http::*;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize)]
struct MyStruct {
#[serde(with = "http_serde_ext::response")]
base: Response<Vec<u8>>,
#[serde(with = "http_serde_ext::request::option", default)]
option: Option<Request<String>>,
#[serde(with = "http_serde_ext::method::vec")]
vec: Vec<Method>,
#[serde(with = "http_serde_ext::uri::vec_deque")]
vec_deque: VecDeque<Uri>,
#[serde(with = "http_serde_ext::header_map::linked_list")]
linked_list: LinkedList<HeaderMap>,
#[serde(with = "http_serde_ext::header_map_generic::hash_map")]
hash_map: HashMap<String, HeaderMap<String>>,
#[serde(with = "http_serde_ext::status_code::btree_map_key")]
btree_map_key: BTreeMap<StatusCode, i32>,
#[serde(with = "http_serde_ext::authority::hash_set")]
hash_set: HashSet<uri::Authority>,
}This library can also be used to manually De/Serialize types if given a
De/Serializer. For example, when using serde_json:
let uri = http::Uri::default();
let serialized = http_serde_ext::uri::serialize(&uri, serde_json::value::Serializer).unwrap();
let deserialized = http_serde_ext::uri::deserialize(serialized).unwrap();
assert_eq!(uri, deserialized);
let responses: Vec<http::Response<()>> = vec![http::Response::default()];
let serialized =
http_serde_ext::response::vec::serialize(&responses, serde_json::value::Serializer)
.unwrap();
let deserialized: Vec<http::Response<()>> =
http_serde_ext::response::vec::deserialize(serialized).unwrap();Modules§
- authority
Serialize/Deserializeforhttp::uri::Authority- header_
map Serialize/Deserializeforhttp::HeaderMap- header_
map_ generic Serialize/Deserializeforhttp::HeaderMap- header_
name Serialize/Deserializeforhttp::HeaderName- header_
value Serialize/Deserializeforhttp::HeaderValue- method
Serialize/Deserializeforhttp::Method- path_
and_ query Serialize/Deserializeforhttp::uri::PathAndQuery- request
Serialize/Deserializeforhttp::Request- response
Serialize/Deserializeforhttp::Response- scheme
Serialize/Deserializeforhttp::uri::Scheme- status_
code Serialize/Deserializeforhttp::StatusCode- uri
Serialize/Deserializeforhttp::Uri- version
Serialize/Deserializeforhttp::Version