Download

Trait Download 

Source
pub trait Download: Sealed {
    // Required method
    fn download<A>(&self, action: A) -> Downloader<'_, Init<'_>>
       where DownloadAction: From<A>;
}
Expand description

Extention trait for downloading mod files.

Required Methods§

Source

fn download<A>(&self, action: A) -> Downloader<'_, Init<'_>>
where DownloadAction: From<A>,

Returns Downloader for saving to file or retrieving the data chunked as Bytes.

The download fails with modio::util::download::Error as source if a primary file, a specific file or a specific version is not found.

§Example
use modio::types::id::Id;
use modio::util::download::{Download, DownloadAction, ResolvePolicy};

// Download the primary file of a mod.
let action = DownloadAction::Primary {
    game_id: Id::new(5),
    mod_id: Id::new(19),
};
modio.download(action).save_to_file("mod.zip").await?;

// Download the specific file of a mod.
let action = DownloadAction::File {
    game_id: Id::new(5),
    mod_id: Id::new(19),
    file_id: Id::new(101),
};
modio.download(action).save_to_file("mod.zip").await?;

// Download the specific version of a mod.
// if multiple files are found then the latest file is downloaded.
// Set policy to `ResolvePolicy::Fail` to return with
// `modio::download::Error::MultipleFilesFound` as source error.
let action = DownloadAction::Version {
    game_id: Id::new(5),
    mod_id: Id::new(19),
    version: "0.1".to_string(),
    policy: ResolvePolicy::Latest,
};
let mut chunked = modio.download(action).chunked().await?;

while let Some(chunk) = chunked.data().await {
    println!("Bytes: {:?}", chunk?);
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§