pub struct Sauce {
pub ext_urls: Vec<String>,
pub title: Option<String>,
pub site: String,
pub index: u32,
pub index_id: u32,
pub similarity: f32,
pub thumbnail: String,
pub additional_fields: Option<Value>,
}
Expand description
A Sauce struct contains one result from a API call made by the Handler.
§Example
use rustnao::{Sauce, HandlerBuilder};
let mut handle = HandlerBuilder::default().api_key("your_api_key").build();
let result : rustnao::Result<Vec<Sauce>> = handle.get_sauce("https://i.pximg.net/img-master/img/2019/02/10/03/11/39/73095123_p0_master1200.jpg", None, None);
Fields§
§ext_urls: Vec<String>
A Vec of Strings representing the external URLs for the image
title: Option<String>
An optional String to represent the title of the image
site: String
A string to represent the site the image is from
index: u32
The official index on SauceNAO for the index the site corresponds to
index_id: u32
The index returned by the SauceNAO API. Usually this is equal to the index
but sometimes it is different (see Sankaku, for example)
similarity: f32
The similarity the image has with the guess
thumbnail: String
A string representing the URL of the thumbnail
additional_fields: Option<Value>
Any additional fields that are specific to the source
Implementations§
Source§impl Sauce
impl Sauce
Sourcepub fn has_empty_url(&self) -> bool
pub fn has_empty_url(&self) -> bool
Returns whether the Sauce struct contains an empty ext_url field.
§Example
use rustnao::{HandlerBuilder, Sauce};
let file = "https://i.imgur.com/W42kkKS.jpg";
let mut handle = HandlerBuilder::default().api_key("your_api_key").build();
handle.set_min_similarity(45);
let result = handle.get_sauce(file, None, None);
if result.is_ok() {
let res : Vec<Sauce> = result.unwrap().into_iter().filter(|sauce| sauce.has_empty_url()).collect();
for i in res {
println!("{:?}", i);
}
}
else {
println!("Failed to make a query.");
}
Examples found in repository?
examples/filter.rs (line 19)
5fn main() {
6 let data = std::fs::read_to_string("config.json").expect("Couldn't read file.");
7 let json: serde_json::Value =
8 serde_json::from_str(data.as_str()).expect("JSON not well formatted.");
9 let api_key = json["api_key"].as_str();
10 let file = "https://i.imgur.com/W42kkKS.jpg";
11
12 if let Some(key) = api_key {
13 let handle = HandlerBuilder::default().api_key(key).build();
14 handle.set_min_similarity(61.31);
15 let result: Vec<Sauce> = handle
16 .get_sauce(file, None, None)
17 .unwrap()
18 .into_iter()
19 .filter(|sauce| !sauce.has_empty_url())
20 .collect(); // Remove empty results
21 for i in result {
22 println!("{:?}", i);
23 }
24 }
25}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Sauce
impl RefUnwindSafe for Sauce
impl Send for Sauce
impl Sync for Sauce
impl Unpin for Sauce
impl UnwindSafe for Sauce
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more