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 durability(self, policy: DurabilityPolicy) -> Self
pub fn durability(self, policy: DurabilityPolicy) -> Self
Override the per-flush durability policy. See DurabilityPolicy for
the three policies and their crash-loss tradeoffs.
The default is DurabilityPolicy::Segment for backward
compatibility. For cloud-sync deployments where the cloud endpoint
holds the durable copy, DurabilityPolicy::Throughput eliminates
the per-flush fsync from the hot path (typically a 5–10× win on fast
storage).
Sourcepub fn cipher(self, cipher: Arc<dyn SegmentCipher + Send + Sync>) -> Self
pub fn cipher(self, cipher: Arc<dyn SegmentCipher + Send + Sync>) -> Self
Install a SegmentCipher so segment payloads are encrypted at rest.
Accepts an Arc so the same cipher can be shared across multiple
buffers or cloned into a recommended_cipher() helper. The canonical
construction pattern is:
use segment_buffer::{AesGcmCipher, SegmentConfig};
use std::sync::Arc;
let cfg = SegmentConfig::builder()
.cipher(Arc::new(AesGcmCipher::new(&[0u8; 32])))
.build();Sourcepub fn build(self) -> SegmentConfig
pub fn build(self) -> SegmentConfig
Materialise the configured SegmentConfig.
Trait Implementations§
Source§impl Clone for SegmentConfigBuilder
impl Clone for SegmentConfigBuilder
Source§fn clone(&self) -> SegmentConfigBuilder
fn clone(&self) -> SegmentConfigBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more