pub struct SegmentConfigBuilder { /* private fields */ }Expand description
Ergonomic builder for SegmentConfig.
SegmentConfig is #[non_exhaustive], so direct struct-literal
construction is forbidden outside the crate. The builder is the
recommended way for callers to override one or two fields without
re-typing every default.
use segment_buffer::{FlushPolicy, SegmentConfig};
use std::time::Duration;
let config = SegmentConfig::builder()
.flush_policy(FlushPolicy::Batch(64))
.compression_level(6)
.build();
assert_eq!(config.flush_policy, FlushPolicy::Batch(64));
assert_eq!(config.compression_level, 6);
// Untouched fields fall back to Default.
assert_eq!(config.max_size_bytes, 10 * 1024 * 1024 * 1024);Implementations§
Source§impl SegmentConfigBuilder
impl SegmentConfigBuilder
Sourcepub fn flush_policy(self, policy: FlushPolicy) -> Self
pub fn flush_policy(self, policy: FlushPolicy) -> Self
Override the auto-flush policy. See FlushPolicy for variants.
Sourcepub fn flush_at_batch_size(self, batch_size: usize) -> Self
pub fn flush_at_batch_size(self, batch_size: usize) -> Self
Convenience: install a FlushPolicy::Batch(batch_size).
Sourcepub fn flush_at_interval(self, interval: Duration) -> Self
pub fn flush_at_interval(self, interval: Duration) -> Self
Convenience: install a FlushPolicy::Interval(interval).
Sourcepub fn flush_at_batch_or_interval(
self,
batch_size: usize,
interval: Duration,
) -> Self
pub fn flush_at_batch_or_interval( self, batch_size: usize, interval: Duration, ) -> Self
Convenience: install a FlushPolicy::BatchOrInterval { .. } with both
triggers set.
Sourcepub fn flush_manually(self) -> Self
pub fn flush_manually(self) -> Self
Convenience: install a FlushPolicy::Manual (no auto-flush).
Sourcepub fn max_size_bytes(self, max_size_bytes: u64) -> Self
pub fn max_size_bytes(self, max_size_bytes: u64) -> Self
Override the disk-usage ceiling that triggers is_overloaded().
Sourcepub fn compression_level(self, compression_level: i32) -> Self
pub fn compression_level(self, compression_level: i32) -> Self
Override the zstd compression level (1–22; 3 is fast with a good ratio).
Sourcepub fn cipher(self, cipher: Box<dyn SegmentCipher>) -> Self
pub fn cipher(self, cipher: Box<dyn SegmentCipher>) -> Self
Install a SegmentCipher so segment payloads are encrypted at rest.
Sourcepub fn build(self) -> SegmentConfig
pub fn build(self) -> SegmentConfig
Materialise the configured SegmentConfig.