Skip to content

remove Borrow<BStr> for String impls (and similar) in a semver compatible release #168

@Xuanwo

Description

@Xuanwo

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions