Skip to main content

Crate rep_move

Crate rep_move 

Source
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:

TypeOutputLength known up front?
RepMoveTYes — ExactSizeIterator
RepMapUYes — ExactSizeIterator
DynamicRepMoveTNo — the closure controls the count
DynamicRepMapUNo — 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 into const fn and Replicator into a const trait; additionally implements the unstable TrustedLen contract and specializes the unstable Iterator::advance_by for RepMove / RepMap. Requires a nightly compiler.

Structs§

DynamicRepMap
Asymmetric dynamically-controlled replicating iterator.
DynamicRepMove
Dynamically-controlled replicating iterator.
RepMap
Asymmetric fixed-length replicating iterator: turns one T into count values of type U.
RepMove
Fixed-length replicating iterator.

Traits§

Replicator
Strategy for producing a replica from a borrowed source.