In the current version of my crate
rtrb I am providing an iterator-based API for reading
&T and writing to
&mut T (and also to
However, I think it would be better to move those items instead of working with references. Changing the "reading" iterator from producing
&T to producing
T is kinda straightforward, but for the "writing" side I've changed the
&mut T producing iterator into a method that takes an iterator that itself produces
I've implemented this in a PR:
For now, I've named the method
populate(), but maybe there is a better name?
Is there a precedent for such a function?
If the underlying container would be able to grow, I would of course implement the
Extend trait, but that's not the case.
Currently, the function signature looks like this:
pub fn populate<I>(self, iter: I) -> usize where I: IntoIterator<Item = T>;
Instead of growing the underlying container, it just stops reading from the iterator when the available storage is full (or when the given iterator is exhausted) and returns the number of moved items.
I was thinking about calling it
fill(), but this might be confused with
slice::fill(), which only takes a single item and clones it multiple times until the slice is filled.
Any other suggestions?