SearchRequest

Struct SearchRequest 

Source
pub struct SearchRequest<'a> {
    pub query: &'a str,
    pub order_by: OrderBy,
    pub categories: Vec<Category>,
    pub number_of_results: usize,
}
Expand description

Represents a search request to be sent to torrent providers.

Fields§

§query: &'a str

The query string to search for.

§order_by: OrderBy

The order by which results are sorted.

§categories: Vec<Category>

Categories to filter results by. Empty means all categories are searched.

§number_of_results: usize

The number of results to retrieve.

Implementations§

Source§

impl<'a> SearchRequest<'a>

Source

pub fn new(query: &'a str) -> Self

Creates a new SearchRequest with the specified query.

Remaining fields get the following default values:

  • order_by: OrderBy::Seeders
  • categories: An empty Vec<Category>
  • number_of_results: 50
§Parameters
  • query: The search term or phrase.
§Returns
  • A new SearchRequest instance.
§Example
use magneto::SearchRequest;

let request = SearchRequest::new("example query");
Examples found in repository?
examples/search.rs (line 9)
4async fn main() {
5    // Only use Knaben provider
6    let magneto = Magneto::default().add_provider(Box::new(Knaben::new()));
7
8    // You can add categories which your search are filtered by.
9    let request = SearchRequest::new("Ubuntu")
10        .add_category(Category::Software)
11        .add_categories(vec![Category::Audio, Category::Movies]);
12
13    // Or initialize the request like this for more customization.
14    let _request = SearchRequest {
15        query: "Debian",
16        order_by: OrderBy::Seeders,
17        categories: vec![Category::Movies],
18        number_of_results: 10,
19    };
20
21    match magneto.search(request).await {
22        Ok(results) => {
23            for torrent in results {
24                println!(
25                    "found: {} from {} with magnet link {} (seeders: {}, peers: {})",
26                    torrent.name,
27                    torrent.provider,
28                    torrent.magnet_link,
29                    torrent.seeders,
30                    torrent.peers,
31                );
32            }
33        }
34        Err(e) => eprintln!("error during search: {:?}", e),
35    }
36}
Source

pub fn add_category(self, category: Category) -> Self

Adds a single category to the SearchRequest.

This method consumes the current instance and returns a new SearchRequest with the added category.

§Parameters
  • category: The Category to add.
§Returns
  • Self: A new SearchRequest instance with the updated category.
§Example
use magneto::{Category, SearchRequest};

let request = SearchRequest::new("example query")
    .add_category(Category::Movies)
    .add_category(Category::Movies); // duplicates are filtered
assert_eq!(request.categories, vec![Category::Movies]);
Examples found in repository?
examples/search.rs (line 10)
4async fn main() {
5    // Only use Knaben provider
6    let magneto = Magneto::default().add_provider(Box::new(Knaben::new()));
7
8    // You can add categories which your search are filtered by.
9    let request = SearchRequest::new("Ubuntu")
10        .add_category(Category::Software)
11        .add_categories(vec![Category::Audio, Category::Movies]);
12
13    // Or initialize the request like this for more customization.
14    let _request = SearchRequest {
15        query: "Debian",
16        order_by: OrderBy::Seeders,
17        categories: vec![Category::Movies],
18        number_of_results: 10,
19    };
20
21    match magneto.search(request).await {
22        Ok(results) => {
23            for torrent in results {
24                println!(
25                    "found: {} from {} with magnet link {} (seeders: {}, peers: {})",
26                    torrent.name,
27                    torrent.provider,
28                    torrent.magnet_link,
29                    torrent.seeders,
30                    torrent.peers,
31                );
32            }
33        }
34        Err(e) => eprintln!("error during search: {:?}", e),
35    }
36}
Source

pub fn add_categories(self, categories: Vec<Category>) -> Self

Adds multiple categories to the SearchRequest.

This method consumes the current instance and returns a new SearchRequest with the added categories.

§Parameters
  • categories: A vector of Category values to add.
§Returns
  • Self: A new SearchRequest instance with the updated categories.
§Example
use magneto::{Category, SearchRequest};

let request = SearchRequest::new("example query").add_categories(vec![
    Category::Movies,
    Category::Anime,
    Category::Anime, // duplicates are filtered
]);
assert_eq!(request.categories, vec![Category::Movies, Category::Anime]);
Examples found in repository?
examples/search.rs (line 11)
4async fn main() {
5    // Only use Knaben provider
6    let magneto = Magneto::default().add_provider(Box::new(Knaben::new()));
7
8    // You can add categories which your search are filtered by.
9    let request = SearchRequest::new("Ubuntu")
10        .add_category(Category::Software)
11        .add_categories(vec![Category::Audio, Category::Movies]);
12
13    // Or initialize the request like this for more customization.
14    let _request = SearchRequest {
15        query: "Debian",
16        order_by: OrderBy::Seeders,
17        categories: vec![Category::Movies],
18        number_of_results: 10,
19    };
20
21    match magneto.search(request).await {
22        Ok(results) => {
23            for torrent in results {
24                println!(
25                    "found: {} from {} with magnet link {} (seeders: {}, peers: {})",
26                    torrent.name,
27                    torrent.provider,
28                    torrent.magnet_link,
29                    torrent.seeders,
30                    torrent.peers,
31                );
32            }
33        }
34        Err(e) => eprintln!("error during search: {:?}", e),
35    }
36}

Trait Implementations§

Source§

impl<'a> Clone for SearchRequest<'a>

Source§

fn clone(&self) -> SearchRequest<'a>

Returns a duplicate 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<'a> Debug for SearchRequest<'a>

Source§

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

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

impl<'a> Serialize for SearchRequest<'a>

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<'a> Freeze for SearchRequest<'a>

§

impl<'a> RefUnwindSafe for SearchRequest<'a>

§

impl<'a> Send for SearchRequest<'a>

§

impl<'a> Sync for SearchRequest<'a>

§

impl<'a> Unpin for SearchRequest<'a>

§

impl<'a> UnwindSafe for SearchRequest<'a>

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, 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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<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,