Skip to main content

FetchConfigBuilder

Struct FetchConfigBuilder 

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

Builder for FetchConfig.

Implementations§

Source§

impl FetchConfigBuilder

Source

pub fn revision(self, revision: &str) -> Self

Sets the git revision (branch, tag, or commit SHA) to download.

Defaults to "main" if not set.

Source

pub fn token(self, token: &str) -> Self

Sets the authentication token.

Source

pub fn token_from_env(self) -> Self

Reads the authentication token from the HF_TOKEN environment variable.

Source

pub fn filter(self, pattern: &str) -> Self

Adds an include glob pattern. Only files matching at least one include pattern will be downloaded.

Can be called multiple times to add multiple patterns.

Source

pub fn exclude(self, pattern: &str) -> Self

Adds an exclude glob pattern. Files matching any exclude pattern will be skipped, even if they match an include pattern.

Can be called multiple times to add multiple patterns.

Source

pub fn concurrency(self, concurrency: usize) -> Self

Sets the number of files to download concurrently.

Defaults to 4.

Source

pub fn output_dir(self, dir: PathBuf) -> Self

Sets a custom output directory for downloaded files.

By default, files are stored in the standard HuggingFace cache directory (~/.cache/huggingface/hub/). When set, the HuggingFace cache hierarchy is created inside this directory instead.

Source

pub fn timeout_per_file(self, duration: Duration) -> Self

Sets the maximum time allowed per file download.

If a single file download exceeds this duration, it is aborted and may be retried according to the retry policy.

Source

pub fn timeout_total(self, duration: Duration) -> Self

Sets the maximum total time for the entire download operation.

If the total download time exceeds this duration, remaining files are skipped and a FetchError::Timeout is returned.

Source

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

Sets the maximum number of retry attempts per file.

Defaults to 3. Set to 0 to disable retries. Uses exponential backoff with jitter (base 300ms, cap 10s).

Source

pub fn verify_checksums(self, verify: bool) -> Self

Enables or disables SHA256 checksum verification after download.

When enabled, downloaded files are verified against the SHA256 hash from HuggingFace LFS metadata. Files without LFS metadata (small config files stored directly in git) are skipped.

Defaults to true.

Source

pub fn chunk_threshold(self, bytes: u64) -> Self

Sets the minimum file size (in bytes) for chunked parallel download.

Files at or above this threshold are downloaded using multiple HTTP Range connections in parallel. Files below use the standard single connection. Defaults to 100 MiB (104_857_600 bytes). Set to u64::MAX to disable chunked downloads entirely.

Source

pub fn connections_per_file(self, connections: usize) -> Self

Sets the number of parallel HTTP connections per large file.

Only applies to files at or above chunk_threshold. Defaults to 8.

Source

pub fn on_progress<F>(self, callback: F) -> Self
where F: Fn(&ProgressEvent) + Send + Sync + 'static,

Sets a progress callback invoked for each progress event.

Source

pub fn build(self) -> Result<FetchConfig, FetchError>

Builds the FetchConfig.

§Errors

Returns FetchError::InvalidPattern if any glob pattern is invalid.

Trait Implementations§

Source§

impl Default for FetchConfigBuilder

Source§

fn default() -> FetchConfigBuilder

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> 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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