sauce_api/
source.rs

1use async_trait::async_trait;
2
3use crate::error::Error;
4
5#[cfg(feature = "saucenao")]
6/// The source for `saucenao.com`. Requires an API key to function.
7pub mod saucenao;
8
9#[cfg(feature = "iqdb")]
10/// The source for `iqdb.org`.
11pub mod iqdb;
12
13/// The generic trait implemented by all sources under this module.
14#[async_trait]
15pub trait Source
16where
17    Self: Sized,
18{
19    /// The argument for [`Source::create`]
20    type Argument;
21
22    /// Searches for the source of a given URL.
23    async fn check(&self, url: &str) -> Result<Output, Error>;
24
25    /// Allows for self-modifying the state of the Source, with an additional 'State' parameter that
26    /// can be passed in.
27    async fn create(argument: Self::Argument) -> Result<Self, Error>;
28}
29
30/// The output of a Source.
31#[derive(Debug, Clone)]
32pub struct Output {
33    /// The original URL provided to the Source.
34    pub original_url: String,
35    /// The results of the search.
36    pub items: Vec<Item>,
37}
38
39/// An individual item from the results gotten.
40#[derive(Debug, Clone)]
41pub struct Item {
42    /// Link to the item. Note: this is not always a direct link to the image, but to a site such as pixiv or danbooru.
43    pub link: String,
44    /// A similarity, usually as `92.4` or whatever the case may be.
45    ///
46    /// # Notes
47    /// A negative value means that a similarity could not be parsed.
48    pub similarity: f32,
49}