I have: data: Vec<String> (unsorted) and some s: &str. I want to know if datacontainss. To my surprise, data.contains(s) does not work because s is not &String. Note that BTreeMap::contains_key allows this.
// impl<T> [T]
pub fn contains(&self, x: &T) -> bool
where
T: PartialEq<T>,
// impl<K, V, A> BTreeMap<K, V, A> where A: Allocator + Clone
pub fn contains_key<Q>(&self, key: &Q) -> bool
where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
For Vec<String>, (&[String]).contains(&String) is the only form allowed by definition.
For BTreeMap<String, V, A>, btreemap.contains_key(&str) is acceptable because of String: Borrow<str> + Ord and str: Ord + ?Sized.
Sure, I understand the signatures. But it is surprising to me that they are the way they are. Probably for historic reasons? maybe because (earlier) type inference handles the non-Borrow one better?