serde
extensions for the http
crate types
Allows serializing and deserializing the following types from http
:
Response
Request
HeaderMap
StatusCode
Uri
Method
HeaderName
HeaderValue
uri::Authority
uri::Scheme
uri::PathAndQuery
Version
- Generic
HeaderMap<T>
where the item is not aHeaderValue
Allows serializing and deserializing the above types wrapped in the following std
container types:
Installation
Run the following Cargo command in your project directory:
cargo add http-serde-ext
Or add the following line to your Cargo.toml:
http-serde-ext = "0.1.6"
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 the 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")]
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")]
btree_map: BTreeMap<i32, StatusCode>,
}
Acknowledgements
This crate is heavily inspired by Kornel's http-serde
.