#serialization #deserialize #urlencoded #fields #urlencode #serde-derive #encode

serde_urlencoded_field

轻松在 serde_dervie 类型中编码字段

62 个稳定版本

1.119.0 2023年12月6日
1.117.0 2023年3月12日
1.109.0 2023年2月9日
1.105.0 2022年12月27日
0.1.0 2019年3月16日

#480编码

Download history 365/week @ 2024-03-09 22/week @ 2024-03-16 12/week @ 2024-03-30

每月214 次下载

Apache-2.0

7KB
114

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.

依赖

~1–1.7MB
~37K SLoC