Hi, I have some troubles in understanding the use of the Borrow trait.
In the first version of the Book section 4.10, following codes are presented to demonstrate the usage of Borrow trait:
fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> where K: Borrow<Q>, Q: Hash + Eq
where K is the key type.
Say K is String, &Q is &str, and String impled Borrow, which means inside the content of
fn get, there must a place
<String as Borrow<str>>::borrow() is called. But why?
Instinctively, shouldn’t the parameter
k be transferred into
String (in some way) and calculate the hash value (from the temp
String), then compared to the inner stored hash value that has already been calculated from the
String-type key values?