#serde #urlencoded #field #json

serde_urlencoded_field

Easily urlencode fields in serde_dervie types

61 stable releases

1.117.0 Mar 12, 2023
1.109.0 Feb 9, 2023
1.105.0 Dec 27, 2022
1.93.0 Nov 23, 2022
0.1.0 Mar 16, 2019

#762 in Parser implementations

Download history 7/week @ 2023-06-05 3/week @ 2023-06-12 78/week @ 2023-06-19 87/week @ 2023-06-26 48/week @ 2023-07-03 5/week @ 2023-07-10 5/week @ 2023-07-17 5/week @ 2023-07-24 5/week @ 2023-07-31 15/week @ 2023-08-07 67/week @ 2023-08-14 7/week @ 2023-08-21 75/week @ 2023-08-28 150/week @ 2023-09-04 74/week @ 2023-09-11 6/week @ 2023-09-18

309 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.7–1.5MB
~34K SLoC