#download #md5 #checksum #macro-derive

macro osmpbf-file-downloader-derive

This crate lets us use OsmPbfFileDownloader derive macro to automatically derive FileDownloader with cleaner syntax for geofabrik osmpbf files. Please see the file-downloader and file-downloader-derive crates for more details.

1 unstable release

0.2.0 Feb 6, 2025

#58 in #md5

Download history 130/week @ 2025-02-04 7/week @ 2025-02-11

137 downloads per month
Used in 9 crates (8 directly)

MIT license

25KB
256 lines

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

We use it like this:

#[derive(OsmPbfFileDownloader)]
enum MyEnum {
    #[geofabrik(spain="madrid-latest.osm.pbf")]
    VariantOne,

    // Could do multiple unit variants, each with its own link
    #[geofabrik(poland="mazowieckie-latest.osm.pbf")]
    VariantTwo,
}

Then, we can do:

#[tokio::main]
async fn main() -> Result<(),Box<dyn Error>> {

    let v1 = MyEnum::VariantOne;
    assert_eq!(v1.download_link(), "https://download.geofabrik.de/europe/spain/madrid-latest.osm.pbf");

    let v2 = MyEnum::VariantTwo;
    assert_eq!(v2.download_link(), "https://download.geofabrik.de/europe/poland/mazowieckie-latest.osm.pbf");

    v1.find_file_locally_or_download_into("target_path").await?;
    Ok(())
}

This crate is a shortcut, similar to the FileDownloader proc macro, given the task of downloading OSM (open streetmap) PBF files follows a common pattern.

It is designed to reduce boilerplate.

Dependencies

~4–6MB
~101K SLoC