Settings

Struct Settings 

Source
pub struct Settings<S> { /* private fields */ }
Expand description

Settings to configure the stream behavior.

Implementations§

Source§

impl<S> Settings<S>

Source

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

How many bytes to download from the stream before allowing read requests. This is used to create a buffer between the read position and the stream position and prevent stuttering.

The default value is 256 kilobytes.

Source

pub fn batch_write_size(self, batch_write_size: NonZeroUsize) -> Self

The maximum number of bytes written to the underlying StorageWriter before yielding to the async runtime. This prevents large writes from performing long blocking operations without giving the scheduler a chance to schedule other tasks.

The default value is 4096.

Source

pub fn retry_timeout(self, retry_timeout: Duration) -> Self

If there is no new data for a duration greater than this timeout, we will attempt to reconnect to the server.

This timeout is designed to help streams recover during temporary network failures, but you may need to increase this if you’re seeing warnings about timeouts in the logs under normal network conditions.

The default value is 5 seconds.

Source

pub fn cancel_on_drop(self, cancel_on_drop: bool) -> Self

If set to true, this will cause the stream download task to automatically cancel when the StreamDownload instance is dropped. It’s useful to disable this if you want to ensure the stream shuts down cleanly.

The default value is true.

Source

pub fn on_progress<F>(self, f: F) -> Self
where F: FnMut(&S, StreamState, &CancellationToken) + Send + Sync + 'static,

Attach a callback function that will be called when a new chunk of the stream is processed. The provided CancellationToken can be used to immediately cancel the stream.

§Example
use reqwest::Client;
use stream_download::Settings;
use stream_download::http::HttpStream;
use stream_download::source::SourceStream;

let settings = Settings::default();
settings.on_progress(|stream: &HttpStream<Client>, state, _| {
    let progress = state.current_position as f32 / stream.content_length().unwrap() as f32;
    println!("progress: {}%", progress * 100.0);
});
Source

pub fn on_reconnect<F>(self, f: F) -> Self
where F: FnMut(&S, &CancellationToken) + Send + Sync + 'static,

Attach a callback function that will be called when the stream reconnects after a failure. The provided CancellationToken can be used to immediately cancel the stream.

Source

pub const fn get_prefetch_bytes(&self) -> u64

Retrieves the configured prefetch bytes

Source

pub const fn get_write_batch_size(&self) -> usize

Retrieves the configured batch write size

Source§

impl Settings<HttpStream<ClientWithMiddleware>>

Source

pub fn add_default_middleware<M>(middleware: M)
where M: Middleware,

Available on crate feature reqwest-middleware only.

Trait Implementations§

Source§

impl<S> Debug for Settings<S>

Source§

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

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

impl<S> Default for Settings<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S> PartialEq for Settings<S>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S> Eq for Settings<S>

Auto Trait Implementations§

§

impl<S> Freeze for Settings<S>

§

impl<S> !RefUnwindSafe for Settings<S>

§

impl<S> Send for Settings<S>

§

impl<S> Sync for Settings<S>

§

impl<S> Unpin for Settings<S>

§

impl<S> !UnwindSafe for Settings<S>

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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
Source§

impl<T> ErasedDestructor for T
where T: 'static,