rep_move
Replicating iterators: build N values from one source with N−1 clones — the
original is moved out on the final iteration, saving one clone for
heap-backed types like Vec, String, or Arc-wrapped data.
#![no_std], zero dependencies.
Example
use RepMove;
let original = vec!;
let copies: = new.collect;
// 3 heap allocations instead of 4 — the last one was moved for free.
assert_eq!;
Types
| Type | Output | Length known up front? |
|---|---|---|
RepMove |
T |
Yes — ExactSizeIterator |
RepMap |
U |
Yes — ExactSizeIterator |
DynamicRepMove |
T |
No — the closure controls the count |
DynamicRepMap |
U |
No — the closure controls the count |
What std can't express: RepMap
core::iter::repeat_n covers the symmetric clone-then-move case. The
*RepMap types go further: the first N−1 items are built from &T and the
final one consumes T, both producing some other type U — the last
conversion reuses the source's resources instead of cloning them first:
use RepMap;
let s = Stringfrom;
let boxes: = new.collect;
The std route would have to clone the String first and convert afterwards,
paying an extra allocation for every item.
O(1) skips
last(), count() and nth() on RepMove / RepMap never materialize
the skipped replicas — iter.last() is just the moved source, with zero
clones, exactly like core::iter::repeat_n.
Full API documentation lives in the source docs: https://docs.rs/rep_move
Feature flags
nightly(disabled by default) — makes the constructorsconst fnandReplicatoraconst trait; additionally implements the unstableTrustedLencontract and specializes the unstableIterator::advance_byforRepMove/RepMap. Requires a nightly compiler.
License
Licensed under the MIT license.