I asked a question a few minutes ago about how to get a reference to the root node of a Rust BTreeMap. I have since learned that this can be done using first_entry
which is a function which returns an Option<OccupiedEntry>
object.
However, I cannot figure out how to map that value to the underlying type.
I thought this might work:
let mut map = BTreeMap::new();
map.insert("A", 5);
map.insert("B", 6);
map.insert("C", 3);
let optional_occupied_entry = map.first_entry();
let f = |x: OccupiedEntry<T, usize>| {
x.get()
};
let optional_value = optional_occupied_entry.map(f);
This is the compiler error I am encountering:
error[E0631]: type mismatch in closure arguments
--> XXX/src/lib.rs:58:29
|
47 | let f2 = |x: std::collections::btree_map::OccupiedEntry<T, usize>| {
| --------------------------------------------------------- found signature defined here
...
58 | let m1 = m1.map(f2);
| --- ^^ expected due to this
| |
| required by a bound introduced by this call
|
= note: expected closure signature `fn(std::collections::btree_map::OccupiedEntry<'_, Reverse<T>, _, _>) -> _`
found closure signature `for<'a> fn(std::collections::btree_map::OccupiedEntry<'a, T, _, _>) -> _`
note: required by a bound in `Option::<T>::map`
--> /home/XXX/.rustup/toolchains/1.70-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1095:12
|
1095 | F: ~const FnOnce(T) -> U,
| ^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Option::<T>::map`