Crate hyper_serde

source ·
Expand description

This crate provides wrappers and convenience functions to make Hyper and Serde work hand in hand.

The supported types are:

  • cookie::Cookie
  • headers_ext::ContentType
  • hyper::header::Headers
  • hyper::StatusCode
  • hyper::Method
  • hyper::Uri
  • mime::Mime

§How do I use a data type with a HeaderMap member with Serde?

Use the serde attributes deserialize_with and serialize_with.

struct MyStruct {
#[serde(deserialize_with = "hyper_serde::deserialize",
serialize_with = "hyper_serde::serialize")]
headers: HeaderMap,
}

§How do I encode a HeaderMap value with serde_json::to_string?

Use the Ser wrapper.

serde_json::to_string(&Ser::new(&headers))

§How do I decode a Method value with serde_json::parse?

Use the De wrapper.

serde_json::parse::<De<Method>>("\"PUT\"").map(De::into_inner)

Use the Serde wrapper. It implements Deref and DerefMut for convenience.

ipc::channel::<Serde<Cookie>>()

Structs§

  • A wrapper to deserialize Hyper types.
  • A wrapper to serialize Hyper types.
  • A convenience wrapper to be used as a type parameter, for example when a Vec<T> need to be passed to serde.

Functions§

  • Deserialises a T value with a given deserializer.
  • Serialises value with a given serializer.
  • Serialises value with a given serializer in a pretty way.