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
impl HandlerBuilder
Sourcepub fn api_key(&mut self, api_key: &str) -> &mut HandlerBuilder
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?
More examples
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}
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}
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}
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}
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}
Sourcepub fn testmode(&mut self, testmode: bool) -> &mut HandlerBuilder
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();
Sourcepub fn db_mask(&mut self, db_mask: Vec<u32>) -> &mut HandlerBuilder
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?
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
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}
Sourcepub fn db_mask_i(&mut self, db_mask_i: Vec<u32>) -> &mut HandlerBuilder
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();
Sourcepub fn db(&mut self, db: u32) -> &mut HandlerBuilder
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();
Sourcepub fn num_results(&mut self, num_results: u32) -> &mut HandlerBuilder
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?
More examples
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}
Sourcepub fn min_similarity<T: Into<f64>>(
&mut self,
min_similarity: T,
) -> &mut HandlerBuilder
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();
Sourcepub fn empty_filter_enabled(
&mut self,
empty_filter_enabled: bool,
) -> &mut HandlerBuilder
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();
Sourcepub fn build(&self) -> Handler
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?
More examples
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}
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}
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}
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}
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
impl Clone for HandlerBuilder
Source§fn clone(&self) -> HandlerBuilder
fn clone(&self) -> HandlerBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more