pub fn download_or_find_file(
    url: &str,
    out_dir: Option<&Path>
) -> Result<PathBuf, DownloadError> {
    use DownloadError::*;

    let url_parsed = Url::parse(url)?;
    let fname = url_fname(&url_parsed);
    if let Some(fname) = fname {
        let out_dir = if let Some(out_dir) = out_dir {
            PathBuf::from(out_dir)
        } else {
            let out_dir = env::var("OUT_DIR").expect("You must provide the output directory when not running from a build script.");
            PathBuf::from(out_dir)
        };
        let path = out_dir.join(fname);
        if !path.exists() {
            let response = reqwest::blocking::get(url)?;
            let content = response.bytes()?;
            let mut bytes = content.bytes();
            let mut dest = fs::File::create(path.clone())?;
            io::copy(&mut bytes, &mut dest)?;
        }
        Ok(path)
    } else {
        Err(NoFileNameError)
    }
}
/// Download file if it doesn't already exist, and return the file's location.
/// 
/// You can use `out_dir` to specify the download directory, otherwise the build script output directory will be used.
/// 
/// Example:
/// 
/// ```
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
/// librarian::download_or_find_file("https://example.com/file.zip", None)?;
/// # Ok(())
/// # }
/// ```

Download file if it doesn't already exist, and return the file's location.
You can use `out_dir` to specify the download directory, otherwise the build script output directory will be used.




Download file if it doesn ' t already exist and return the file ' s location . You can use ` out_dir ` to specify the download directory otherwise the build script output directory will be used .
pub fn download_or_find_file(
    url: &str,
    out_dir: Option<&Path>
) -> Result<PathBuf, DownloadError> {
    use DownloadError::*;
    let url_parsed = Url::parse(url)?;
    let fname = url_fname(&url_parsed);
    if let Some(fname) = fname {
        let out_dir = if let Some(out_dir) = out_dir {
            PathBuf::from(out_dir)
        } else {
            let out_dir = env::var("OUT_DIR").expect("You must provide the output directory when not running from a build script.");
            PathBuf::from(out_dir)
        };
        let path = out_dir.join(fname);
        if !path.exists() {
            let response = reqwest::blocking::get(url)?;
            let content = response.bytes()?;
            let mut bytes = content.bytes();
            let mut dest = fs::File::create(path.clone())?;
            io::copy(&mut bytes, &mut dest)?;
        }
        Ok(path)
    } else {
        Err(NoFileNameError)
    }
}
pub fn download_or_find_file ( url : & str , out_dir : Option < & Path > ) -> Result < PathBuf , DownloadError > { use DownloadError :: * ; let url_parsed = Url :: parse ( url ) ? ; let fname = url_fname ( & url_parsed ) ; if let Some ( fname ) = fname { let out_dir = if let Some ( out_dir ) = out_dir { PathBuf :: from ( out_dir ) } else { let out_dir = env :: var ( " " ) . expect ( " " ) ; PathBuf :: from ( out_dir ) } ; let path = out_dir . join ( fname ) ; if ! path . exists ( ) { let response = reqwest :: blocking :: get ( url ) ? ; let content = response . bytes ( ) ? ; let mut bytes = content . bytes ( ) ; let mut dest = fs :: File :: create ( path . clone ( ) ) ? ; io :: copy ( & mut bytes , & mut dest ) ? ; } Ok ( path ) } else { Err ( NoFileNameError ) } }
Download file if it doesn't already exist, and return the file's location.
Download file if it doesn ' t already exist and return the file ' s location .
url
&str
out_dir
Option<&Path>
url
&str
out_dir
Option<&Path>
fn run() -> result<(), box<dyn std::error::error>> {

None
ok(())

None
}

None