On page 297 of Programming Rust you can find the following
impl HashMap<K, V> where K: Eq + Hash
{
fn get<Q: ?Sized>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Eq + Hash
}
I've seen this before where ?Sized
is written by itself, and the rest of trait bounds are on a different line? Is this a convention? As I understand it, the above is effectively the same as the following?
impl HashMap<K, V> where K: Eq + Hash
{
fn get<Q>(&self, key: &Q) -> Option<&V>
where K: Borrow<Q>,
Q: Eq + Hash + ?Sized
}
Why is ?Sized
split off? You can see this in a similar example on page 295,
...
where T: AsRef<U>
T: ?Sized, U: ?Sized
...