Skip to main content

SequentialBatchProcessor

Struct SequentialBatchProcessor 

Source
pub struct SequentialBatchProcessor<Item> { /* private fields */ }
Expand description

Processes batch items sequentially by invoking a Consumer per item.

The processor stores the supplied consumer as a BoxConsumer and invokes it on the caller thread in input order. Consumer panics are not caught; they propagate to the caller and no BatchProcessResult is produced. Progress updates are emitted only between items.

§Type Parameters

  • Item - Item type consumed by the stored consumer.
use qubit_batch::{
    BatchProcessor,
    SequentialBatchProcessor,
};

let mut processor = SequentialBatchProcessor::new(|item: &i32| {
    assert!(*item > 0);
});

let result = processor
    .process([1, 2, 3])
    .expect("array length should be exact");

assert!(result.is_success());

Implementations§

Source§

impl<Item> SequentialBatchProcessor<Item>

Source

pub const DEFAULT_REPORT_INTERVAL: Duration

Default interval between progress callbacks.

Source

pub fn new<C>(consumer: C) -> Self
where C: Consumer<Item> + 'static,

Creates a sequential consumer-backed batch processor.

§Parameters
  • consumer - Consumer invoked once for each input item.
§Returns

A processor storing consumer as a BoxConsumer.

Source

pub fn builder<C>(consumer: C) -> SequentialBatchProcessorBuilder<Item>
where C: Consumer<Item> + 'static,

Creates a builder for configuring a sequential consumer-backed processor.

§Parameters
  • consumer - Consumer invoked once for each input item.
§Returns

A builder initialized with default settings.

Source

pub const fn report_interval(&self) -> Duration

Returns the configured progress-report interval.

§Returns

The minimum time between due-based running progress callbacks.

Source

pub fn reporter(&self) -> &Arc<dyn ProgressReporter>

Returns the configured progress reporter.

§Returns

A shared reference to the configured progress reporter.

Source

pub const fn consumer(&self) -> &BoxConsumer<Item>

Returns the stored consumer.

§Returns

A shared reference to the boxed consumer.

Source

pub fn into_consumer(self) -> BoxConsumer<Item>

Consumes this processor and returns the stored consumer.

§Returns

The boxed consumer used by this processor.

Trait Implementations§

Source§

impl<Item> BatchProcessor<Item> for SequentialBatchProcessor<Item>

Source§

fn process_with_count<I>( &mut self, items: I, count: usize, ) -> Result<BatchProcessResult, Self::Error>
where I: IntoIterator<Item = Item>,

Processes items sequentially on the caller thread.

§Parameters
  • items - Item source for the batch.
  • count - Declared number of items expected from items.
§Returns

A result with completed and processed counts equal to the number of consumer calls when the input source yields exactly count items.

§Errors

Returns BatchProcessError::CountShortfall when the source ends before count, or BatchProcessError::CountExceeded when the source yields an extra item. Extra items are observed but not passed to the consumer.

§Panics

Propagates any panic raised by the stored consumer or the configured progress reporter.

Source§

type Error = BatchProcessError

Error returned by this processor.
Source§

fn process<I>(&mut self, items: I) -> Result<BatchProcessResult, Self::Error>
where I: IntoIterator<Item = Item>, I::IntoIter: ExactSizeIterator,

Processes items as one batch using its exact iterator length. Read more

Auto Trait Implementations§

§

impl<Item> Freeze for SequentialBatchProcessor<Item>

§

impl<Item> !RefUnwindSafe for SequentialBatchProcessor<Item>

§

impl<Item> !Send for SequentialBatchProcessor<Item>

§

impl<Item> !Sync for SequentialBatchProcessor<Item>

§

impl<Item> Unpin for SequentialBatchProcessor<Item>

§

impl<Item> UnsafeUnpin for SequentialBatchProcessor<Item>

§

impl<Item> !UnwindSafe for SequentialBatchProcessor<Item>

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> 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, 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.