use std::{fs, io};
#[derive(thiserror::Error, Debug)]
pub enum DownloadError {
#[error("HTTP error while downloading file: {0}")]
HttpError(#[from] Box<ureq::Error>),
#[error("IO error while downloading file: {0}")]
IoError(#[from] std::io::Error),
}
pub fn download_file(
uri: impl AsRef<str>,
destination: impl AsRef<std::path::Path>,
) -> Result<(), DownloadError> {
let response = ureq::get(uri.as_ref()).call().map_err(Box::new)?;
let mut reader = response.into_reader();
let mut file = fs::File::create(destination.as_ref())?;
io::copy(&mut reader, &mut file)?;
Ok(())
}