-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for HashMap<K, V, S> (for other S)
This makes the implementations for Serialize and JsonSerialize accept different S values instead of the default RandomState specified by `std::collections::HashMap`. It also adds an example with the ahash crate. Closes #87
- Loading branch information
1 parent
65c5c75
commit d3191ae
Showing
9 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#[cfg(feature = "ahash")] | ||
fn main() { | ||
use ahash::HashMap; | ||
use merde::json; | ||
|
||
let mut h = HashMap::default(); | ||
h.insert("street".to_string(), "123 Main St".to_string()); | ||
h.insert("city".to_string(), "Anytown".to_string()); | ||
h.insert("state".to_string(), "CA".to_string()); | ||
h.insert("zip".to_string(), "12345".to_string()); | ||
|
||
println!("h: {:#?}", h); | ||
|
||
let serialized = json::to_string(&h); | ||
println!("serialized: {}", serialized); | ||
|
||
let deserialized: HashMap<String, String> = json::from_str(&serialized).unwrap(); | ||
println!("deserialized: {:#?}", deserialized); | ||
|
||
assert_eq!(h, deserialized); | ||
|
||
assert_eq!(deserialized.get("street"), Some(&"123 Main St".to_string())); | ||
assert_eq!(deserialized.get("city"), Some(&"Anytown".to_string())); | ||
assert_eq!(deserialized.get("state"), Some(&"CA".to_string())); | ||
assert_eq!(deserialized.get("zip"), Some(&"12345".to_string())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters