I have a question to ask. Let's take a look at the following code:
use std::collection::BTreeMap;
fn main() {
let mut hm: BTreeMap<String, String> = BTreeMap::new();
hm.insert("asdf".to_owned(), "zxcv".to_owned());
println!("{:?}", hm.get("asdf"));
}
So, despite the fact that BTreeMap keeps Strings it accepts other types which can be compared to the key type.
But it's not just the case with Vec<T>. Hence the following code would be a blunder:
fn main() {
let v: Vec<String> = vec!["hello".to_owned()];
println!("{:?}", v.binary_search("hello"));
}
This snippet would just fail to be compiled, since binary_search calls for a reference to the exactly same type of the provided value. I'm somewhat bewildered why.