Crates.io | detrim |
lib.rs | detrim |
version | 0.1.4 |
source | src |
created_at | 2024-05-19 12:45:01.387429 |
updated_at | 2024-10-10 12:41:32.142513 |
description | Automatic string trimming with serde |
homepage | |
repository | https://github.com/x52dev/detrim |
max_upload_size | |
id | 1244898 |
size | 35,542 |
detrim
Deserialization trimming for strings in serde models.
#[derive(Debug, serde::Deserialize)]
struct Form {
#[serde(deserialize_with = "detrim::string")]
name: String,
}
let form = serde_json::from_str::<Form>(r#"{ "name": "ferris" }"#).unwrap();
assert_eq!(form.name, "ferris");
let form = serde_json::from_str::<Form>(r#"{ "name": " ferris " }"#).unwrap();
assert_eq!(form.name, "ferris");