pub struct BatchWriter<T> { /* private fields */ }Expand description
Performance optimization utilities
Inspired by SierraDB’s focus on high-throughput operations.
§Design Principles
- Batch operations for reduced overhead
- Minimal allocations
- Zero-copy where possible
- Lock-free when feasible Batch writer for high-throughput ingestion
Accumulates items in a buffer and flushes when:
- Buffer reaches capacity
- Time threshold exceeded
- Explicit flush called
§Example
ⓘ
let mut writer = BatchWriter::new(100, Duration::from_millis(100));
writer.add(item)?;
if writer.should_flush() {
writer.flush()?;
}Implementations§
Source§impl<T> BatchWriter<T>
impl<T> BatchWriter<T>
Sourcepub fn new(capacity: usize, flush_interval: Duration) -> Self
pub fn new(capacity: usize, flush_interval: Duration) -> Self
Create new batch writer
§Arguments
capacity: Maximum items before auto-flushflush_interval: Maximum time between flushes
Sourcepub fn should_flush(&self) -> bool
pub fn should_flush(&self) -> bool
Check if buffer should be flushed
Sourcepub fn time_since_flush(&self) -> Duration
pub fn time_since_flush(&self) -> Duration
Get time since last flush
Auto Trait Implementations§
impl<T> Freeze for BatchWriter<T>
impl<T> RefUnwindSafe for BatchWriter<T>where
T: RefUnwindSafe,
impl<T> Send for BatchWriter<T>where
T: Send,
impl<T> Sync for BatchWriter<T>where
T: Sync,
impl<T> Unpin for BatchWriter<T>where
T: Unpin,
impl<T> UnwindSafe for BatchWriter<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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> 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 more