passionfruit

Crates.iopassionfruit
lib.rspassionfruit
version1.1.0
sourcesrc
created_at2022-08-12 16:14:21.671878
updated_at2022-08-13 03:31:11.727859
descriptionAn image downloader package with automatic file extension appendage.
homepage
repositoryhttps://github.com/Nowaaru/passionfruit
max_upload_size
id644184
size40,712
Noire (Nowaaru)

documentation

README

passionfruit

A Rust library to fetch files off of the interwebs and optionally download them. In short, a reqwest interface.

Example

Similarly to reqwest, this example uses the module tokio to make the fn main() asynchronous:

use tokio;
use directories;
use passionfruit;


#[tokio::main]
async fn main() {
    match passionfruit::Download::new("https://i.imgur.com/ISfpRae.jpeg").start().await {
        Ok(result) => {
            if let Ok(_) = result.write_to(
                directories::UserDirs::new()
                    .unwrap()
                    .desktop_dir()
                    .unwrap()
                    .to_str()
                    .unwrap()
                    .to_string(),
                    "lol".to_string()
                ) {
                println!("Download completed!")
            }
        }
        Err(why) => panic!("It appears something went wrong: {}", why)
    }
}

An example which doesn't use tokio but instead futures:

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)
    }
}
Commit count: 11

cargo fmt