SearchBuilder

Struct SearchBuilder 

Source
pub struct SearchBuilder<T = ()> { /* private fields */ }
Expand description

A builder for building the URL with the indicated parameters This struct works with TypeState Programming so the SearchBuilder::build_url() method can’t be called unless search_type is set.

The facets field works as a conjunction (AND) of disjunctions (OR):

Implementations§

Source§

impl SearchBuilder<()>

Source§

impl<T> SearchBuilder<T>

Source

pub fn facets(self, facets: impl Into<FacetsConjunction>) -> Self

Sets the facets.

Source

pub fn game_versions<E>(self, versions: impl IntoIterator<Item = E>) -> Self
where E: ToString,

Sets the game versions filter for the project version search.

§Parameters
  • versions: A type that can be iterated and its items implements ToString.
§Returns

Returns an updated instance of the SearchBuilder with the specified game versions filter applied.

§Example
use rrhodium::*;
let builder = SearchBuilder::new()
    .search_type(SearchType::ProjectVersion {id: "example_id".to_owned(), loaders:
    Some(vec!["fabric".to_string()])})
    .game_versions(["1.16.5", "1.17.1"])
    .build_url();
§Restrictions

This method is only available when the search type is ProjectVersion. Attempting to call this method for other search types will do nothing.

§Panics

This method does not panic.

§Notes
  • The game_versions parameter allows you to filter results to only include project versions compatible with the specified game versions.
  • Ensure that you are using this method within the ProjectVersion search context, as it is specifically designed for filtering versions based on game compatibility.
Source

pub fn add_game_version(self, version: impl ToString) -> Self

Adds a single game version to the game versions filter for the project version search.

This method allows you to append a game version to the existing filter criteria in the SearchBuilder. The version is added to the vector of game versions that will be used to filter the results of the search.

§Parameters
  • version: Whatever type that can be transformed into a String.
§Returns

Returns an updated instance of the SearchBuilder with the specified game version added to the filter criteria.

§Example
use rrhodium::{SearchType, SearchBuilder};
let builder = SearchBuilder::new()
    .search_type(SearchType::ProjectVersion {id: "example_id".to_string(), loaders: Some(vec!["fabric".to_string()])})
    .add_game_version("1.16.5")
    .add_game_version("1.17.1")
    .build_url();
§Restrictions

This method only has an effect when the search type is ProjectVersion. If used with a different search type, it will have no impact on the search builder and will silently ignore the call.

§Panics

This method does not panic.

§Errors

This method does not return errors.

§Notes
  • Ensure that this method is called within the ProjectVersion search context, as it is specifically designed for filtering project versions based on game compatibility.
  • If used outside the ProjectVersion context, the method will not modify the builder and will effectively do nothing.
Source

pub fn search_type(self, search_type: SearchType) -> SearchBuilder<SearchType>

Source§

impl SearchBuilder<SearchType>

Source

pub fn build_url(self) -> String

Generates the URL based on the SearchBuilder object.

This method constructs a URL for the Modrinth API using various parameters from the SearchBuilder struct. It supports multiple search types and query parameters, and it constructs the URL accordingly.

§Returns

A String representing the constructed URL.

§Examples
use rrhodium::*;
    let search_builder: String = SearchBuilder::new()
    .search_type(QueryBuilder::new().limit(10).offset(5).build())
    .build_url();
assert_eq!("https://api.modrinth.com/v2/search?limit=10&offset=5", &search_builder);

Trait Implementations§

Source§

impl<T: Default> Default for SearchBuilder<T>

Source§

fn default() -> SearchBuilder<T>

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

Auto Trait Implementations§

§

impl<T> Freeze for SearchBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for SearchBuilder<T>
where T: RefUnwindSafe,

§

impl<T> Send for SearchBuilder<T>
where T: Send,

§

impl<T> Sync for SearchBuilder<T>
where T: Sync,

§

impl<T> Unpin for SearchBuilder<T>
where T: Unpin,

§

impl<T> UnwindSafe for SearchBuilder<T>
where T: UnwindSafe,

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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.