async fn download_file(url: &str, tmp_dir: &tempfile::TempDir) -> Result<String> {
    //  Download the file and wait for the download to be completed
    println!("url to download: '{}'", url);
    let response = reqwest::get(url).await ? ;

    //  Get the last part of the URL as filename, or firmware.bin
    let fname = response
        .url()
        .path_segments()
        .and_then(|segments| segments.last())
        .and_then(|name| if name.is_empty() { None } else { Some(name) })
        .unwrap_or("firmware.bin");

    //  Create the temporary pathname
    let fname = tmp_dir.path().join(fname);
    println!("will be located under: '{:?}'", fname);
    let mut dest = File::create(fname.clone()) ? ;

    //  Copy the downloaded data to the temporary pathname
    let content = response.bytes().await ? ;
    std::io::copy(&mut content.as_ref(), &mut dest) ? ;
    Ok(fname.to_str().unwrap().to_string())
}
/// Download the URL to the temporary directory. Returns the downloaded pathname.
Download the URL to the temporary directory. Returns the downloaded pathname.
Download the URL to the temporary directory . Returns the downloaded pathname .
async fn download_file(url: &str, tmp_dir: &tempfile::TempDir) -> Result<String> {
    //  Download the file and wait for the download to be completed
    println!("url to download: '{}'", url);
    let response = reqwest::get(url).await ? ;
    //  Get the last part of the URL as filename, or firmware.bin
    let fname = response
        .url()
        .path_segments()
        .and_then(|segments| segments.last())
        .and_then(|name| if name.is_empty() { None } else { Some(name) })
        .unwrap_or("firmware.bin");
    //  Create the temporary pathname
    let fname = tmp_dir.path().join(fname);
    println!("will be located under: '{:?}'", fname);
    let mut dest = File::create(fname.clone()) ? ;
    //  Copy the downloaded data to the temporary pathname
    let content = response.bytes().await ? ;
    std::io::copy(&mut content.as_ref(), &mut dest) ? ;
    Ok(fname.to_str().unwrap().to_string())
}
async fn download_file ( url : & str , tmp_dir : & tempfile :: TempDir ) -> Result < String > { //  Download the file and wait for the download to be completed println ! ( " " url ) ; let response = reqwest :: get ( url ) . await ? ; //  Get the last part of the URL as filename, or firmware.bin let fname = response . url ( ) . path_segments ( ) . and_then ( | segments | segments . last ( ) ) . and_then ( | name | if name . is_empty ( ) { None } else { Some ( name ) } ) . unwrap_or ( " " ) ; //  Create the temporary pathname let fname = tmp_dir . path ( ) . join ( fname ) ; println ! ( " " fname ) ; let mut dest = File :: create ( fname . clone ( ) ) ? ; //  Copy the downloaded data to the temporary pathname let content = response . bytes ( ) . await ? ; std :: io :: copy ( & mut content . as_ref ( ) , & mut dest ) ? ; Ok ( fname . to_str ( ) . unwrap ( ) . to_string ( ) ) }
Download the URL to the temporary directory.
Download the URL to the temporary directory .
url
&str
tmp_dir
&tempfile::TempDir
url
&str
tmp_dir
&tempfile::TempDir