Crate serde_urlencoded_field[−][src]
Percent encode fields.
This is a helper module for using serde_drive. It allows you to specify that some fields in your type will be automatically percent-encoded on serialization and percent-decoded on deserialization.
Example
use serde_derive::{Deserialize, Serialize}; #[derive(Debug, Deserialize, Serialize, PartialEq)] struct Item { #[serde(with="serde_urlencoded_field::path_segment")] id: String, mime: String, } let item = Item { id: "my/item".to_string(), mime: "application/wasm".to_string(), }; let json = serde_json::to_string(&item).unwrap(); assert_eq!(json, r#"{"id":"my%2Fitem","mime":"application/wasm"}"#); let item2: Item = serde_json::from_str(&json).unwrap(); assert_eq!(item2, item);
Types
serde_urlencoded_field can serialize anything that implements AsRef<[u8]>
,
including String
, &str
, Vec<u8>
and &[u8]
.
serde_urlencoded_field can deserialize into String
and Vec<u8>
. Other
types can be added by implementing the FromPercentDecode trait.
Modules
default | |
path_segment | |
query | |
simple | |
userinfo |
Traits
FromPercentDecode |