Given the following code:
use bstr;
#[test]
fn test_bstr() {
let mut m = HashMap::new();
m.insert("hello".to_owned(), 42i8);
assert!(m.get(bstr::BStr::new("hello")).copied() == Some(42));
}
We expect it to pass, but failed. The root cause is: the hash for identical content differs between a String and bytes.
Considering Borrow
's requirement:
In particular Eq, Ord and Hash must be equivalent for borrowed and owned values: x.borrow() == y.borrow()
should give the same result as x == y
.
Is it safe to implement Borrow<BStr> for String
?