Skip to main content

FetchOptions

Struct FetchOptions 

Source
pub struct FetchOptions {
    pub checksum: Option<[u8; 32]>,
    pub retry_policy: RetryPolicy,
    pub expected_bytes: Option<u64>,
    pub resume_offset: Option<u64>,
    pub headers: Arc<[(String, String)]>,
    pub on_progress: Option<ProgressCallback>,
    pub retry_delay_provider: Option<RetryDelayProvider>,
}
Expand description

Configuration for HTTP fetching operations.

§Examples

use pulith_fetch::FetchOptions;
use std::time::Duration;

let options = FetchOptions::default()
    .max_retries(5)
    .retry_backoff(Duration::from_millis(200))
    .header("Authorization", "Bearer token");

Fields§

§checksum: Option<[u8; 32]>

Expected SHA-256 checksum for verification (optional). If provided, the download will be verified and will fail on mismatch.

§retry_policy: RetryPolicy

Retry execution policy for transient transfer failures.

§expected_bytes: Option<u64>

Expected total bytes for this transfer, when known by caller.

§resume_offset: Option<u64>

Resume offset in bytes. When set, fetcher will request Range: bytes=<offset>-.

§headers: Arc<[(String, String)]>

Custom HTTP headers to include with requests.

Headers are sent with every request, including retries.

Default: empty

§on_progress: Option<ProgressCallback>

Progress callback invoked on state transitions and chunk writes.

The callback is invoked:

  • On phase transitions (Connecting → Downloading → Verifying → Committing → Completed)
  • After each chunk write (during Downloading phase, typically every ~8KB)
  • After each retry attempt (back to Connecting phase)

The callback receives a reference to avoid cloning on every invocation.

Default: None

§retry_delay_provider: Option<RetryDelayProvider>

Optional runtime delay provider for retry backoff sleeping.

When absent, fetcher uses the crate default async sleep mechanism.

Implementations§

Source§

impl FetchOptions

Source

pub fn checksum(self, checksum: Option<[u8; 32]>) -> Self

Set the expected checksum.

§Examples
use pulith_fetch::FetchOptions;

let hash = [0u8; 32]; // Your expected SHA-256
let options = FetchOptions::default().checksum(Some(hash));
Source

pub fn max_retries(self, max_retries: u32) -> Self

Set the maximum number of retries.

§Examples
use pulith_fetch::FetchOptions;

let options = FetchOptions::default().max_retries(5);
Source

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

Set the base retry backoff duration.

§Examples
use pulith_fetch::FetchOptions;
use std::time::Duration;

let options = FetchOptions::default()
    .retry_backoff(Duration::from_millis(200));
Source

pub fn retry_policy(self, retry_policy: RetryPolicy) -> Self

Set the full retry policy object directly.

Source

pub fn expected_bytes(self, expected_bytes: Option<u64>) -> Self

Set expected transfer size for progress/reporting without HEAD lookup.

Source

pub fn resume_offset(self, resume_offset: Option<u64>) -> Self

Set resume offset in bytes for ranged fetch.

Source

pub fn header(self, key: impl Into<String>, value: impl Into<String>) -> Self

Add a single custom HTTP header.

§Examples
use pulith_fetch::FetchOptions;

let options = FetchOptions::default()
    .header("Authorization", "Bearer token")
    .header("User-Agent", "MyApp/1.0");
Source

pub fn headers(self, headers: Vec<(String, String)>) -> Self

Set multiple custom HTTP headers at once.

This replaces any existing headers.

§Examples
use pulith_fetch::FetchOptions;

let headers = vec![
    ("Authorization".to_string(), "Bearer token".to_string()),
    ("User-Agent".to_string(), "MyApp/1.0".to_string()),
];
let options = FetchOptions::default().headers(headers);
Source

pub fn on_progress( self, on_progress: Arc<dyn Fn(&Progress) + Send + Sync>, ) -> Self

Set the progress callback.

§Examples
use pulith_fetch::{FetchOptions, FetchPhase};
use std::sync::Arc;

let options = FetchOptions::default()
    .on_progress(Arc::new(|progress| {
        match progress.phase {
            FetchPhase::Downloading => {
                if let Some(pct) = progress.percentage() {
                    println!("Progress: {:.1}%", pct);
                }
            }
            FetchPhase::Completed => println!("Done!"),
            _ => {}
        }
    }));
Source

pub fn retry_delay_provider(self, provider: RetryDelayProvider) -> Self

Set an async retry-delay provider for runtime-agnostic backoff handling.

Trait Implementations§

Source§

impl Clone for FetchOptions

Source§

fn clone(&self) -> FetchOptions

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FetchOptions

Source§

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

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

impl Default for FetchOptions

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