pub struct ItemBatcher {
pub max_items_per_batch: usize,
pub max_bytes_per_batch: usize,
}Expand description
Configuration for batching items in map operations.
Fields§
§max_items_per_batch: usizeMaximum number of items per batch.
max_bytes_per_batch: usizeMaximum total bytes per batch.
Implementations§
Source§impl ItemBatcher
impl ItemBatcher
Sourcepub fn new(max_items_per_batch: usize, max_bytes_per_batch: usize) -> Self
pub fn new(max_items_per_batch: usize, max_bytes_per_batch: usize) -> Self
Creates a new ItemBatcher with the specified limits.
Sourcepub fn batch<T: Serialize + Clone>(&self, items: &[T]) -> Vec<(usize, Vec<T>)>
pub fn batch<T: Serialize + Clone>(&self, items: &[T]) -> Vec<(usize, Vec<T>)>
Batches items according to configuration, respecting both item count and byte limits.
This method groups items into batches where each batch:
- Contains at most
max_items_per_batchitems - Has an estimated total size of at most
max_bytes_per_batchbytes
Item size is estimated using JSON serialization via serde_json.
§Arguments
items- The slice of items to batch
§Returns
A vector of (start_index, batch) tuples where:
start_indexis the index of the first item in the batch from the original slicebatchis a vector of cloned items in that batch
§Example
use durable_execution_sdk::ItemBatcher;
let batcher = ItemBatcher::new(2, 1024);
let items = vec!["a", "b", "c", "d", "e"];
let batches = batcher.batch(&items);
// Items are grouped into batches of at most 2 items each
assert_eq!(batches.len(), 3);
assert_eq!(batches[0], (0, vec!["a", "b"]));
assert_eq!(batches[1], (2, vec!["c", "d"]));
assert_eq!(batches[2], (4, vec!["e"]));Trait Implementations§
Source§impl Clone for ItemBatcher
impl Clone for ItemBatcher
Source§fn clone(&self) -> ItemBatcher
fn clone(&self) -> ItemBatcher
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ItemBatcher
impl Debug for ItemBatcher
Auto Trait Implementations§
impl Freeze for ItemBatcher
impl RefUnwindSafe for ItemBatcher
impl Send for ItemBatcher
impl Sync for ItemBatcher
impl Unpin for ItemBatcher
impl UnsafeUnpin for ItemBatcher
impl UnwindSafe for ItemBatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreCreates a shared type from an unshared type.