Struct Sauce

Source
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

Source

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§

Source§

impl Debug for Sauce

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Sauce

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,