Struct HandlerBuilder

Source
pub struct HandlerBuilder { /* private fields */ }
Expand description

A builder to create a Handler for RustNAO usage.

§Example

use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().api_key("your_api_key").num_results(999).db(999).build();

Implementations§

Source§

impl HandlerBuilder

Source

pub fn api_key(&mut self, api_key: &str) -> &mut HandlerBuilder

Sets the API key used for searches for the Handler. If this is not set then a blank API key is used, instead of your personal one.

§Arguments
  • api_key - A string reference representing your API key.
§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().api_key("your_api_key").build();
Examples found in repository?
examples/error.rs (line 7)
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}
More examples
Hide additional examples
examples/local.rs (line 13)
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 = "./examples/local/test.jpg";
11
12    if let Some(key) = api_key {
13        let handle = HandlerBuilder::default().api_key(key).build();
14        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
15        for i in result {
16            println!("{:?}", i);
17        }
18    }
19}
examples/simple_example.rs (line 13)
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        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
15        for i in result {
16            println!("{:?}", i);
17        }
18    }
19}
examples/only_pixiv.rs (line 14)
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()
14            .api_key(key)
15            .db_mask([Handler::PIXIV].to_vec())
16            .build();
17        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
18        for i in result {
19            println!("{:?}", i);
20        }
21    }
22}
examples/manga_page.rs (line 14)
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://s5.mangadex.org/data/f2cf04ff9fbd5374c20d1cd5a555efed/x2.png";
11
12    if let Some(key) = api_key {
13        let mut handle_builder = HandlerBuilder::default();
14        handle_builder.api_key(key);
15        let handle = handle_builder.build();
16        handle.set_empty_filter(true);
17        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
18        println!("{}", result.to_json_pretty().unwrap());
19    }
20}
examples/filter.rs (line 13)
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}
Source

pub fn testmode(&mut self, testmode: bool) -> &mut HandlerBuilder

Sets whether testmode should be enabled on searches for the Handler. If this is on, then each index will output at most one result. If this is unset then it is set to off by default.

§Arguments
  • testmode - A boolean representing whether you want testmode to be set to on (true) or off (false).
§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().testmode(true).build();
Source

pub fn db_mask(&mut self, db_mask: Vec<u32>) -> &mut HandlerBuilder

Sets which database indices you want included on search for the Handler. If both db and db_mask are not set, then every index is checked (db_mask_i will still apply).

§Arguments
  • db_mask - A vector of u32s representing the database indices you wish to have included in your search.
§Examples
use rustnao::{Handler, HandlerBuilder};
let handle = HandlerBuilder::default().db_mask([1, 2, Handler::PIXIV].to_vec()).build();
Examples found in repository?
examples/only_pixiv.rs (line 15)
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()
14            .api_key(key)
15            .db_mask([Handler::PIXIV].to_vec())
16            .build();
17        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
18        for i in result {
19            println!("{:?}", i);
20        }
21    }
22}
More examples
Hide additional examples
examples/simple_json.rs (line 17)
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        // Specifying our key, test_mode set to 0, only want to see Pixiv and Sankaku using a mask, nothing excluded, no one specific source, and 999 results at most
14        let handle = HandlerBuilder::default()
15            .api_key(key)
16            .num_results(999)
17            .db_mask([Handler::PIXIV, Handler::SANKAKU_CHANNEL].to_vec())
18            .build();
19        let result = handle.get_sauce_as_pretty_json(file, None, None).unwrap();
20        println!("{}", result);
21    }
22}
Source

pub fn db_mask_i(&mut self, db_mask_i: Vec<u32>) -> &mut HandlerBuilder

Sets which database indices you want excluded on search for the Handler.

§Arguments
  • db_mask_i - A vector of u32s representing the database indices you wish to have excluded in your search.
§Examples
use rustnao::{Handler, HandlerBuilder};
let handle = HandlerBuilder::default().db_mask_i([1, 2, Handler::PIXIV].to_vec()).build();
Source

pub fn db(&mut self, db: u32) -> &mut HandlerBuilder

Sets a database index to be searched for the Handler. If both db and db_mask are not set, then every index is checked (db_mask_i will still apply).

§Arguments
  • db - A u32 representing which database index you want included. Set it to 999 to include every index.
§Examples
use rustnao::{Handler, HandlerBuilder};
let handle = HandlerBuilder::default().db(Handler::PIXIV).build();
Examples found in repository?
examples/error.rs (line 8)
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}
Source

pub fn num_results(&mut self, num_results: u32) -> &mut HandlerBuilder

Sets the maximum number of results you want returned on search for the Handler. You can change this number per-search. If this is not set, by default this is set to return at most 999 results.

§Arguments
  • num_results - A u32 value representing how many results you want returned.
§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().num_results(10).build();
Examples found in repository?
examples/error.rs (line 9)
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}
More examples
Hide additional examples
examples/simple_json.rs (line 16)
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        // Specifying our key, test_mode set to 0, only want to see Pixiv and Sankaku using a mask, nothing excluded, no one specific source, and 999 results at most
14        let handle = HandlerBuilder::default()
15            .api_key(key)
16            .num_results(999)
17            .db_mask([Handler::PIXIV, Handler::SANKAKU_CHANNEL].to_vec())
18            .build();
19        let result = handle.get_sauce_as_pretty_json(file, None, None).unwrap();
20        println!("{}", result);
21    }
22}
Source

pub fn min_similarity<T: Into<f64>>( &mut self, min_similarity: T, ) -> &mut HandlerBuilder

Sets he minimum similarity for results by default for the Handler. You can change this number per-search. If this is not set, by default it is 0.0 (no minimum similarity).

§Arguments
  • min_similarity : A number that can be cast into a f64 representing the minimum similarity (in percent) of a result to be returned.
§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().min_similarity(50.5).build();
Source

pub fn empty_filter_enabled( &mut self, empty_filter_enabled: bool, ) -> &mut HandlerBuilder

Sets whether to enable an empty filter by default for the Handler. If this is not set, by default it is false.

§Arguments
  • empty_filter_enabled : A boolean representing whether you want empty URL search results to be filtered out by default.
§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().empty_filter_enabled(true).build();
Source

pub fn build(&self) -> Handler

Builds the HandlerBuilder, returning a Handler that can be used to search.

§Examples
use rustnao::HandlerBuilder;
let handle = HandlerBuilder::default().api_key("your_api_key").db(999).num_results(50).build();
Examples found in repository?
examples/error.rs (line 10)
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}
More examples
Hide additional examples
examples/local.rs (line 13)
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 = "./examples/local/test.jpg";
11
12    if let Some(key) = api_key {
13        let handle = HandlerBuilder::default().api_key(key).build();
14        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
15        for i in result {
16            println!("{:?}", i);
17        }
18    }
19}
examples/simple_example.rs (line 13)
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        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
15        for i in result {
16            println!("{:?}", i);
17        }
18    }
19}
examples/only_pixiv.rs (line 16)
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()
14            .api_key(key)
15            .db_mask([Handler::PIXIV].to_vec())
16            .build();
17        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
18        for i in result {
19            println!("{:?}", i);
20        }
21    }
22}
examples/manga_page.rs (line 15)
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://s5.mangadex.org/data/f2cf04ff9fbd5374c20d1cd5a555efed/x2.png";
11
12    if let Some(key) = api_key {
13        let mut handle_builder = HandlerBuilder::default();
14        handle_builder.api_key(key);
15        let handle = handle_builder.build();
16        handle.set_empty_filter(true);
17        let result: Vec<Sauce> = handle.get_sauce(file, None, None).unwrap();
18        println!("{}", result.to_json_pretty().unwrap());
19    }
20}
examples/filter.rs (line 13)
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 Clone for HandlerBuilder

Source§

fn clone(&self) -> HandlerBuilder

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HandlerBuilder

Source§

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

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

impl Default for HandlerBuilder

Source§

fn default() -> HandlerBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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,