Skip to main content

SegmentConfigBuilder

Struct SegmentConfigBuilder 

Source
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

Source

pub fn flush_policy(self, policy: FlushPolicy) -> Self

Override the auto-flush policy. See FlushPolicy for variants.

Source

pub fn flush_at_batch_size(self, batch_size: usize) -> Self

Convenience: install a FlushPolicy::Batch(batch_size).

Source

pub fn flush_at_interval(self, interval: Duration) -> Self

Convenience: install a FlushPolicy::Interval(interval).

Source

pub fn flush_at_batch_or_interval( self, batch_size: usize, interval: Duration, ) -> Self

Convenience: install a FlushPolicy::BatchOrInterval { .. } with both triggers set.

Source

pub fn flush_manually(self) -> Self

Convenience: install a FlushPolicy::Manual (no auto-flush).

Source

pub fn max_size_bytes(self, max_size_bytes: u64) -> Self

Override the disk-usage ceiling that triggers is_overloaded().

Source

pub fn compression_level(self, compression_level: i32) -> Self

Override the zstd compression level (1-22; default 3, fast with a good ratio).

Source

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).

Source

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();
Source

pub fn recommended_cipher(self, key: [u8; 32]) -> Self

Available on crate feature encryption only.

Install the cipher this crate recommends for new buffers.

Available only under the encryption feature. Picks XChaCha20Poly1305Cipher (24-byte extended nonce, no 2³²-message limit per key, constant-time on hosts without AES-NI). Legacy AES-GCM segments still decrypt through AesGcmCipher; the two formats are byte-distinguishable only by which cipher the buffer was opened with.

§Example
use segment_buffer::SegmentConfig;
let cfg = SegmentConfig::builder()
    .recommended_cipher([0u8; 32])
    .build();
Source

pub fn build(self) -> SegmentConfig

Materialise the configured SegmentConfig.

Trait Implementations§

Source§

impl Clone for SegmentConfigBuilder

Source§

fn clone(&self) -> SegmentConfigBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SegmentConfigBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more