Open ewoolsey opened 1 year ago
Currently, this crate uses "stable Rust" only and our MSRV does not allow us to use "const generics". "Const generics" might be usable in a few months (I guess I'm not sure) when we raise the MSRV but it seems very unlikely to me we would use nightly features (from my understanding mainly to limit the maintenance burden).
Hey thanks for the info @Philippe-Cholet . Const generics are obviously necessary for this to work, but this could still be implemented without the rest of the nightly features (although not quite as cleanly). Perhaps let's pick this conversation back up when const generics are usable.
Copy and pasted from the libs-team api change proposal which likely isn't going through. Would this crate be a good place for an addition like this?
Proposal
Problem statement
This feature would allow finding, returning, and potentially mapping, multiple &muts within a single iterator using a convenient const generic array syntax
Motivation, use-cases
Credit to @cuviper on the rust internals forum for building out most of this implementation.
This is a very general addition and could support many use cases. Currently it is rather difficult and cumbersome to find multiple &muts from an iterator.
Solution sketches
This feature would introduce 2 new methods on
Iterator<Item = &mut T>
.find_many
takes an iterator and return multiple mutable references to the items which match the predicate.Example
find_map_many
takes an iterator and returns multiple mutable references to the items which match the predicate. The items which match the predicate are then mapped to a different &mut. This is particularly useful when doing something similar to a key value search.Example
For both methods an option containing an array to the &muts would be returned. The None variant would represent cases where there are no matching items in the iterator for every key. Each key provided requires a unique Item.
This feature will make make handling mutable iterators much more ergonomic and should prevent programmers from rearranging code in unintuitive ways just to make the borrow checker happy. This should result in more natural layout of functions.
Reference-level explanation
These methods rely on two nightly features of rust to be enabled.
array_try_map
andinline_const
.