62 stable releases
1.119.0 | Dec 6, 2023 |
---|---|
1.117.0 | Mar 12, 2023 |
1.109.0 | Feb 9, 2023 |
1.105.0 | Dec 27, 2022 |
0.1.0 | Mar 16, 2019 |
#777 in Encoding
214 downloads per month
7KB
114 lines
serde_urlencoded_field
lib.rs
:
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.
Dependencies
~0.7–1.6MB
~35K SLoC