1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
use BatchProcessResult;
/// Processes a declared batch of data items.
///
/// This trait models processors that receive data items directly. A processor
/// may insert records into a database, send them to a remote service, or apply
/// any other batch-level operation chosen by the implementation.
///
/// ```rust
/// use std::time::Duration;
///
/// use qubit_batch::{
/// BatchProcessResult,
/// BatchProcessResultBuilder,
/// BatchProcessor,
/// };
///
/// struct CountItems;
///
/// impl BatchProcessor<i32> for CountItems {
/// type Error = &'static str;
///
/// fn process<I>(&mut self, items: I, count: usize) -> Result<BatchProcessResult, Self::Error>
/// where
/// I: IntoIterator<Item = i32>,
/// {
/// let processed = items.into_iter().count();
/// BatchProcessResultBuilder::builder(count)
/// .completed_count(processed)
/// .processed_count(processed)
/// .chunk_count(1)
/// .elapsed(Duration::ZERO)
/// .build()
/// .map_err(|_| "invalid process result")
/// }
/// }
///
/// let result = CountItems
/// .process([1, 2, 3], 3)
/// .expect("processor should accept the batch");
///
/// assert!(result.is_success());
/// ```
///
/// # Type Parameters
///
/// * `Item` - The data item type consumed by this processor.
///