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:
capacityis rounded up to at least4 * block_sizebytes so each block read fits in the ring with three more behind it.block_sizeis rounded up to4 KiBif smaller (an innerreadof a few bytes per syscall would dominate the worker’s wall time).lookback_num / lookback_denis 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_timeoutis clamped to a minimum of 1 ms so a misconfiguredDuration::ZEROdoes not flap reads throughTimedOutimmediately.
Implementations§
Source§impl BufferedSourceBuilder
impl BufferedSourceBuilder
Sourcepub fn capacity(self, bytes: usize) -> Self
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.
Sourcepub fn block_size(self, bytes: usize) -> Self
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.
Sourcepub fn prefetch_timeout(self, dt: Duration) -> Self
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.
Sourcepub fn lookback_fraction(self, num: u32, den: u32) -> Self
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.
Sourcepub fn build(self, inner: Box<dyn ReadSeek>) -> Result<BufferedSource>
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
impl Clone for BufferedSourceBuilder
Source§fn clone(&self) -> BufferedSourceBuilder
fn clone(&self) -> BufferedSourceBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more