file-downloader-derive

Crates.iofile-downloader-derive
lib.rsfile-downloader-derive
version0.2.0
created_at2024-12-21 06:56:27.745841+00
updated_at2025-02-06 21:49:58.528407+00
descriptionThis crate lets us use FileDownloader derive macro. We can use it to facilitate flexible downloading of files.
homepage
repositoryhttps://github.com/klebs6/klebs-general
max_upload_size
id1490790
size59,904
(klebs6)

documentation

README

This is a proc-macro crate for the FileDownloader trait found in the file-downloader crate.

We use it like this:

#[derive(FileDownloader)]
enum MyEnum {
    #[download_link("https://example.com/data1.pbf")]
    VariantOne,

    // Could do multiple unit variants, each with its own link
    #[download_link("https://example.com/data2.pbf")]
    VariantTwo,
}

fn main() {
    let v1 = MyEnum::VariantOne;
    assert_eq!(v1.download_link(), "https://example.com/data1.pbf");

    let v2 = MyEnum::VariantTwo;
    assert_eq!(v2.download_link(), "https://example.com/data2.pbf");
}

Then, we can do:

fn main() -> Result<(),DownloadError> {
    let v1 = MyEnum::VariantOne;
    assert_eq!(v1.download_link(), "https://example.com/data1.pbf");
    v1.find_file_locally_or_download_into("target_path").await?;
    Ok(())
}
Commit count: 634

cargo fmt