| Crates.io | http-serde-ext-ios |
| lib.rs | http-serde-ext-ios |
| version | 1.0.0 |
| created_at | 2024-11-25 21:22:24.34738+00 |
| updated_at | 2024-11-25 21:22:24.34738+00 |
| description | serde support for http crate types Request, Response, Uri, StatusCode, HeaderMap, Method, in Option or other collections |
| homepage | https://github.com/integration-os/http-serde-ext-ios |
| repository | https://github.com/integration-os/http-serde-ext-ios |
| max_upload_size | |
| id | 1460781 |
| size | 105,938 |
serde extensions for the http crate typesAllows serializing and deserializing the following types from http:
ResponseRequestHeaderMapStatusCodeUriMethodHeaderNameHeaderValueuri::Authorityuri::Schemeuri::PathAndQueryVersionHeaderMap<T> where the item is not a HeaderValueAllows serializing and deserializing the above types wrapped in the following std container types:
OptionResult in the Ok positionVecVecDequeLinkedListHashMap as the Key for all except HeaderMap, Request, and Response. As the Value for all types.BTreeMap as the Key only for HeaderValue, StatusCode, and Version. As the Value for all types.HashSet for all except HeaderMap, Request, and ResponseBTreeSet only for HeaderValue, StatusCode, and VersionRun the following Cargo command in your project directory:
cargo add http-serde-ext-ios
Or add the following line to your Cargo.toml:
http-serde-ext-ios = "1.0.2"
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_ios::response")]
base: Response<Vec<u8>>,
#[serde(with = "http_serde_ext_ios::request::option", default)]
option: Option<Request<String>>,
#[serde(with = "http_serde_ext_ios::method::vec")]
vec: Vec<Method>,
#[serde(with = "http_serde_ext_ios::uri::vec_deque")]
vec_deque: VecDeque<Uri>,
#[serde(with = "http_serde_ext_ios::header_map::linked_list")]
linked_list: LinkedList<HeaderMap>,
#[serde(with = "http_serde_ext_ios::header_map_generic::hash_map")]
hash_map: HashMap<String, HeaderMap<String>>,
#[serde(with = "http_serde_ext_ios::status_code::btree_map_key")]
btree_map: BTreeMap<StatusCode, i32>,
#[serde(with = "http_serde_ext_ios::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_ios::uri::serialize(&uri, serde_json::value::Serializer).unwrap();
let deserialized = http_serde_ext_ios::uri::deserialize(serialized).unwrap();
assert_eq!(uri, deserialized);
let mut responses: Vec<http::Response<()>> = vec![http::Response::default()];
let serialized =
http_serde_ext_ios::response::vec::serialize(&responses, serde_json::value::Serializer)
.unwrap();
let mut deserialized: Vec<http::Response<()>> =
http_serde_ext_ios::response::vec::deserialize(serialized).unwrap();
let original = responses.remove(0).into_parts();
let deserialized = deserialized.remove(0).into_parts();
assert_eq!(original.0.status, deserialized.0.status);
assert_eq!(original.0.version, deserialized.0.version);
assert_eq!(original.0.headers, deserialized.0.headers);
assert_eq!(original.1, deserialized.1);
Forked from Andrew Toth's to add patches and fixes as needed.