Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
leroyguillaume committed Jul 23, 2023
1 parent 3bf13ce commit 6e12d7d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Support trim
* `String`
* `Vec<String>`
* `BTreeSet<String>`
* `Option<String>`


Expand Down Expand Up @@ -55,5 +56,21 @@ fn main() {
let json = r#"{"name":[" ","foo","b ar","hello "," rust"]}"#;
let foo = serde_json::from_str::<VecFoo>(json).unwrap();
assert_eq!(foo.name, vec!["", "foo", "b ar", "hello", "rust"]);

#[derive(Deserialize)]
struct BTreeSetFoo {
#[serde(deserialize_with = "btreeset_string_trim")]
name: BTreeSet<String>,
}
let json = r#"{"name":[" ","foo","b ar","hello "," rust"]}"#;
let foo = serde_json::from_str::<BTreeSetFoo>(json).unwrap();
let expected: BTreeSet<String> = BTreeSet::from_iter([
"".into(),
"foo".into(),
"b ar".into(),
"hello".into(),
"rust".into(),
]);
assert_eq!(foo.name, expected);
}
```

0 comments on commit 6e12d7d

Please sign in to comment.