ParallelIteratorSource

Struct ParallelIteratorSource 

Source
pub struct ParallelIteratorSource<Source>
where Source: IntoParallelSource,
{ /* private fields */ }
Expand description

Source that ingests items into a stream using the maximum parallelism. The items are from the iterators returned by a generating function.

Each replica (i.e. each core) will have a different iterator. The iterator are produced by a generating function passed to the ParallelIteratorSource::new method.

Implementations§

Source§

impl<S> ParallelIteratorSource<S>

Source

pub fn new(generator: S) -> Self

Create a new source that ingest items into the stream using the maximum parallelism available.

The function passed as argument is cloned in each core, and called to get the iterator for that replica. The first parameter passed to the function is a 0-based index of the replica, while the second is the total number of replicas.

§Example
// generate the numbers from 0 to 99 using multiple replicas
let n = 100;
let source = ParallelIteratorSource::new(move |id, instances| {
    let chunk_size = (n + instances - 1) / instances;
    let remaining = n - n.min(chunk_size * id);
    let range = remaining.min(chunk_size);
     
    let start = id * chunk_size;
    let stop = id * chunk_size + range;
    start..stop
});
let s = env.stream(source);

Trait Implementations§

Source§

impl<S> Clone for ParallelIteratorSource<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<Source> Debug for ParallelIteratorSource<Source>
where Source: IntoParallelSource,

Source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Source> Display for ParallelIteratorSource<Source>
where Source: IntoParallelSource,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S> Operator for ParallelIteratorSource<S>
where S: IntoParallelSource, S::Iter: Send, <S::Iter as Iterator>::Item: Send,

Source§

type Out = <<S as IntoParallelSource>::Iter as Iterator>::Item

Source§

fn setup(&mut self, metadata: &mut ExecutionMetadata<'_>)

Setup the operator chain. This is called before any call to next and it’s used to initialize the operator. When it’s called the operator has already been cloned and it will never be cloned again. Therefore it’s safe to store replica-specific metadata inside of it. Read more
Source§

fn next(&mut self) -> StreamElement<Self::Out>

Take a value from the previous operator, process it and return it.
Source§

fn structure(&self) -> BlockStructure

A more refined representation of the operator and its predecessors.
Source§

impl<S> Source for ParallelIteratorSource<S>
where S: IntoParallelSource, S::Iter: Send, <S::Iter as Iterator>::Item: Send,

Source§

fn replication(&self) -> Replication

The maximum parallelism offered by this operator.

Auto Trait Implementations§

§

impl<Source> Freeze for ParallelIteratorSource<Source>
where Source: Freeze, <Source as IntoParallelSource>::Iter: Freeze,

§

impl<Source> RefUnwindSafe for ParallelIteratorSource<Source>
where Source: RefUnwindSafe, <Source as IntoParallelSource>::Iter: RefUnwindSafe,

§

impl<Source> Send for ParallelIteratorSource<Source>
where <Source as IntoParallelSource>::Iter: Send,

§

impl<Source> Sync for ParallelIteratorSource<Source>
where Source: Sync, <Source as IntoParallelSource>::Iter: Sync,

§

impl<Source> Unpin for ParallelIteratorSource<Source>
where Source: Unpin, <Source as IntoParallelSource>::Iter: Unpin,

§

impl<Source> UnwindSafe for ParallelIteratorSource<Source>
where Source: UnwindSafe, <Source as IntoParallelSource>::Iter: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneDebuggableStorage for T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CloneableStorage for T
where T: Any + Send + Sync + Clone,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Data for T
where T: Clone + Send + 'static,

Source§

impl<T> DebuggableStorage for T
where T: Any + Send + Sync + Debug,