4 ms·
You don't need to do all that much, you can use `Option` with `into_iter` paired with `flatten` instead: fn neighbors_with_send_capacity(&self, a: N, capac
by the_mitsuhiko 2y ago
You don't need to do all that much, you can use `Option` with `into_iter` paired with `flatten` instead:
fn neighbors_with_send_capacity(&self, a: N, capacity: u128) -> impl Iterator<Item = &N> + '_ {
self.nodes
.get(&a)
.map(|m| m.keys())
.into_iter()
.flatten()
.filter(move |b| self.get_send_capacity(&a, b) >= capacity)
}
The only downside is that I believe `size_hint` is not properly forwarded.
- OptionOfT 2y agoForgive the non-versioned link: https://doc.rust-lang.org/1.81.0/src/core/iter/adapters/flatten.rs.html#618 https://doc.rust-lang.org/1.81.0/src/core/iter/adapters/flat... I think it does work correctly.