A Rust library to fetch files off of the interwebs and optionally download them.
In short, a reqwest
interface.
Similarly to reqwest
, this example uses the module tokio
to make the fn main()
asynchronous:
```rs use tokio; use directories; use passionfruit;
async fn main() { match passionfruit::Download::new("https://i.imgur.com/ISfpRae.jpeg").start().await { Ok(result) => { if let Ok() = result.writeto( directories::UserDirs::new() .unwrap() .desktopdir() .unwrap() .tostr() .unwrap() .tostring(), "lol".tostring() ) { println!("Download completed!") } } Err(why) => panic!("It appears something went wrong: {}", why) } } ```
An example which doesn't use tokio
but instead futures
:
```rs use futures; use directories; use passionfruit;
fn main() { let download = futures::executor::block_on( passionfruit::Download::new("https://i.imgur.com/8iiChzd.jpeg").start(), );
match download {
Ok(result) => {
if let Some(dirs) = directories::UserDirs::new() {
result.write_to(
dirs.document_dir()
.unwrap()
.to_str()
.unwrap()
.to_string(),
"out".to_string()
).unwrap();
}
},
Err(why) => panic!("An error occured: {}", why)
}
} ```