63 stable releases

1.121.0 Aug 22, 2025
1.119.0 Dec 6, 2023
1.117.0 Mar 12, 2023
1.105.0 Dec 27, 2022
0.1.0 Mar 16, 2019

#628 in Encoding

Download history 35/week @ 2025-07-09 43/week @ 2025-07-16 16/week @ 2025-07-23 32/week @ 2025-07-30 162/week @ 2025-08-06 191/week @ 2025-08-13 324/week @ 2025-08-20 49/week @ 2025-08-27 203/week @ 2025-09-03 454/week @ 2025-09-10 227/week @ 2025-09-17 63/week @ 2025-09-24 118/week @ 2025-10-01 120/week @ 2025-10-08 251/week @ 2025-10-15 144/week @ 2025-10-22

641 downloads per month

Apache-2.0

7KB
114 lines

serde_urlencoded_field

Docs


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.6–1.6MB
~34K SLoC