file_downloader/
lib.rs

1#![allow(unused_variables)]
2#[macro_use] mod imports; use imports::*;
3
4x!{compute_and_verify_md5}
5x!{download_file}
6x!{download_file_with_md5}
7x!{errors}
8x!{extract_md5_from_filename}
9x!{fetch_md5_for_link}
10x!{file_utils}
11x!{filename_with_md5}
12x!{find_local_file}
13x!{find_file_locally_or_download}
14x!{get_extension_intelligent}
15
16pub trait DownloadLink {
17
18    /// Return the associated OSM PBF download link
19    fn download_link(&self) -> &str;
20}
21
22pub trait Md5DownloadLink: DownloadLink {
23
24    fn md5_download_link(&self) -> Option<Cow<'_,str>> {
25        Some(Cow::Owned(format!("{}.md5", self.download_link())))
26    }
27}
28
29#[async_trait]
30pub trait FileDownloader: Md5DownloadLink {
31
32    /// Obtain the associated PBF file locally, downloading if necessary.
33    /// By default, this uses the `find_or_download` function provided by this crate.
34    async fn find_file_locally_or_download_into(&self, directory: impl AsRef<Path> + Send + Sync) -> Result<PathBuf, DownloadError> {
35        find_file_locally_or_download_into(
36            self.download_link(), 
37            self.md5_download_link().as_deref(), 
38            directory
39        ).await
40    }
41}