__sliced__

Macro __sliced__ 

Source
macro_rules! __sliced__ {
    ($($tt:tt)*) => { ... };
}
Expand description

Transforms a live collection with a computation relying on a slice of another live collection. This is useful for reading a snapshot of an asynchronously updated collection while processing another collection, such as joining a stream with the latest values from a singleton.

§Syntax

The sliced! macro takes in a closure-like syntax specifying the live collections to be sliced and the body of the transformation. Each use statement indicates a live collection to be sliced, along with a non-determinism explanation. Optionally, a style can be specified to control how the live collection is sliced (e.g., atomically). All use statements must appear before the body.

let stream = sliced! {
    let name1 = use(collection1, nondet!(/** explanation */));
    let name2 = use::atomic(collection2, nondet!(/** explanation */));

    // arbitrary statements can follow
    let intermediate = name1.map(...);
    intermediate.cross_singleton(name2)
};

§Example with two collections

let singleton = process.singleton(q!(5));
let stream = process.source_iter(q!(vec![1, 2, 3]));
let out: Stream<(i32, i32), _> = sliced! {
    let batch_of_req = use(stream, nondet!(/** test */));
    let latest_singleton = use(singleton, nondet!(/** test */));

    let mapped = batch_of_req.map(q!(|x| x * 2));
    mapped.cross_singleton(latest_singleton)
};