Expand description
Replicating iterators: N−1 clones followed by moving the original.
When you need several identical values built from one source, the naïve
approach clones all N. This crate clones N−1 and moves the original
on the final iteration — saving one clone for heap-backed types like
Vec, String, or Arc-wrapped data.
Four iterator types are provided:
| 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 |
The *RepMove types yield the source type itself. The *RepMap types
are asymmetric: the first N−1 items are built from &T, and the final
one consumes T — both producing some other type U.
§Quick start
use rep_move::RepMove;
let original = vec![1, 2, 3];
let copies: Vec<_> = RepMove::new(original, Vec::clone, 4).collect();
// 3 heap allocations instead of 4 — the last one was moved for free.
assert_eq!(copies.len(), 4);§Feature flags
nightly(disabled by default) — turns the constructors intoconst fnandReplicatorinto aconst trait; additionally implements the unstableTrustedLencontract and specializes the unstableIterator::advance_byforRepMove/RepMap. Requires a nightly compiler.
Structs§
- Dynamic
RepMap - Asymmetric dynamically-controlled replicating iterator.
- Dynamic
RepMove - Dynamically-controlled replicating iterator.
- RepMap
- Asymmetric fixed-length replicating iterator: turns one
Tintocountvalues of typeU. - RepMove
- Fixed-length replicating iterator.
Traits§
- Replicator
- Strategy for producing a replica from a borrowed source.