-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Description
In the following case, the NewType wrapped Ustr doesn't work ergonomically with HashMap though with Borrow being implemented because the hash value of &str is different from the hash value of Ustr, while we are not able to specify the hasher used for the Ustr, it would be nice to add support of specifying the hasher here so the hash value used for the hashmap is the same as Ustr used internally.
This is tangential to the this issue #39 but closed.
#[derive(Hash, Eq, PartialEq, Debug, Clone)]
struct Name(ustr::Ustr);
impl std::borrow::Borrow<str> for Name {
fn borrow(&self) -> &str {
self.0.as_str()
}
}
fn main() {
let mut map = std::collections::HashMap::new();
map.insert(Name(ustr::Ustr::from("John")), 32);
let result = map.contains_key("John");
assert_eq!(result, true); // panic as result is false
}Metadata
Metadata
Assignees
Labels
No labels