Skip to main content

clone

Function clone 

Source
pub fn clone<T>(t: T) -> Cloned<T>
Expand description

Wraps a top-level bounded singleton-like live collection (a Singleton or an Optional), such as a configuration value fixed when the flow is built, to be read in every slice.

Unlike snapshot, this takes no non-determinism guard: a bounded collection has a single immutable value, so every slice observes that same value. Unbounded collections are rejected at compile time (use snapshot for those).

The slice is a bounded Singleton (or Optional) on the tick of the sliced! body, as produced by Singleton::clone_into_tick. The value is cloned into every tick, so T must implement Clone; reading it by reference instead requires snapshots of singleton-like collections to return references (hydro#2415), and a use::reference style is planned for that.

let offset = process.singleton(q!(100));
let input = process.source_iter(q!(vec![1, 2, 3]));
sliced! {
    let batch = use::batch(input, nondet!(/** test */));
    let offset = use::clone(offset);
    batch.cross_singleton(offset).map(q!(|(x, offset)| x + offset))
}
// 101, 102, 103