Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chp7: rust_snippet: show type parameter declaration for 'fn get' #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/chp7/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,33 @@ assert_eq!(map.get(&2), None);
Based on the above, you might expect the `get` method's signature to look like this for `BTreeMap<K, V>`:

```rust,ignore
/// Returns a reference to the value corresponding to the key.
pub fn get(&self, key: &K) -> Option<&V>
where
K: Ord
{
// ...function body here...
impl<K, V> BTreeMap<K, V> {
/// Returns a reference to the value corresponding to the key.
pub fn get(&self, key: &K) -> Option<&V>
where
K: Ord
{
// ...function body here...
}
// ... rest of the methods
}

```

But it doesn't.
The real `get` method has this signature[^BTreeMapGet2]:

```rust,ignore
/// Returns a reference to the value corresponding to the key.
pub fn get<Q>(&self, key: &Q) -> Option<&V>
where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
{
// ...function body here...
impl<K, V> BTreeMap<K, V> {
/// Returns a reference to the value corresponding to the key.
pub fn get<Q>(&self, key: &Q) -> Option<&V>
where
K: Borrow<Q> + Ord,
Q: Ord + ?Sized,
{
// ...function body here...
}
// ... rest of the methods
}
```

Expand Down