Skip to main content

BufferedSourceBuilder

Struct BufferedSourceBuilder 

Source
pub struct BufferedSourceBuilder { /* private fields */ }
Expand description

Builder for BufferedSource. Exposes every prefetch tunable for callers whose source has a non-default latency or transfer profile; callers that just want a sensible buffer can stay on BufferedSource::new.

Defaults match BufferedSource::new: 1 MiB capacity, DEFAULT_BLOCK block size, DEFAULT_PREFETCH_TIMEOUT reader timeout, and DEFAULT_LOOKBACK_NUM / DEFAULT_LOOKBACK_DEN lookback fraction.

All tunables are clamped on build so the worker is always able to make forward progress regardless of the values handed in:

  • capacity is rounded up to at least 4 * block_size bytes so each block read fits in the ring with three more behind it.
  • block_size is rounded up to 4 KiB if smaller (an inner read of a few bytes per syscall would dominate the worker’s wall time).
  • lookback_num / lookback_den is clamped to the range [0, 1) — a denominator of zero is treated as “no lookback” and a numerator matching the denominator is dropped to “(den - 1) / den” so the reader always has at least one byte of forward window.
  • prefetch_timeout is clamped to a minimum of 1 ms so a misconfigured Duration::ZERO does not flap reads through TimedOut immediately.

Implementations§

Source§

impl BufferedSourceBuilder

Source

pub fn new() -> Self

New builder with all knobs at their defaults.

Source

pub fn capacity(self, bytes: usize) -> Self

Set the ring capacity in bytes. Will be clamped up to at least 4 * block_size on build so the ring always holds several worker blocks.

Source

pub fn block_size(self, bytes: usize) -> Self

Maximum bytes the worker reads from the inner source per syscall. Clamped up to 4 KiB on build. Larger values reduce per-syscall overhead at the cost of coarser-grained ring fills.

Source

pub fn prefetch_timeout(self, dt: Duration) -> Self

Maximum time a Read will block waiting for the worker to push fresh bytes. TimedOut is surfaced on expiry. Clamped up to 1 ms on build.

Source

pub fn lookback_fraction(self, num: u32, den: u32) -> Self

Fraction of the ring kept behind the reader as lookback so short backward seeks hit the ring. Expressed as num/den to avoid a floating-point knob (the worker uses integer division internally). 0/N disables lookback entirely. N/N is clamped to (N-1)/N so the ring keeps a forward window.

Source

pub fn build(self, inner: Box<dyn ReadSeek>) -> Result<BufferedSource>

Build a BufferedSource from this builder and an inner source. Spawns one worker thread that takes ownership of inner.

Trait Implementations§

Source§

impl Clone for BufferedSourceBuilder

Source§

fn clone(&self) -> BufferedSourceBuilder

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 BufferedSourceBuilder

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BufferedSourceBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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, 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> 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.