error/
error.rs

1//! Example where errors are caught
2
3use rustnao::{HandlerBuilder, Result};
4
5fn get_source(file: &str) -> Result<String> {
6    let handle = HandlerBuilder::default()
7        .api_key("")
8        .db(999)
9        .num_results(99)
10        .build();
11    handle.get_sauce_as_pretty_json(file, None, None)
12}
13
14fn get_source_string(file: &str) -> String {
15    let result = get_source(file);
16    match result {
17        Ok(res) => res,
18        Err(err) => err.to_string(),
19    }
20}
21
22fn main() {
23    let file = "https://i.imgur.com/W42kkKS.jpg";
24    let invalid_file = "https://j.jmgur.jpg";
25    println!("{}", get_source_string(file));
26    println!("{}", get_source_string(invalid_file));
27}