Function prelate_rs::search
source · pub fn search(query: impl AsRef<str>) -> SearchQuery
Expand description
Returns a SearchQuery
. Used to query the /players/search
endpoint.
Note: the query must contain at least 3 characters.
§Params
query
is a search query (e.g. a player’s username or part of a username).
§Examples
§Fuzzy Search
In the following example, we collect the first 10 players who match the
search query "jiglypuf"
into a Vec
:
use prelate_rs::{futures::StreamExt, search};
let stream = search("jiglypuf")
.get(10)
.await
.expect("query should succeed");
let profiles = stream.collect::<Vec<_>>().await;
for profile in profiles {
// Do something with each profile.
}
§Exact Search
In the following example, we search for the player who matches exactly the
search query "[DEBILS] HousedHorse"
:
use prelate_rs::{futures::StreamExt, search};
let mut stream = search("[DEBILS] HousedHorse")
.with_exact(Some(true))
.get(1)
.await
.expect("query should succeed");
let profile = stream
.next()
.await
.expect("there should be at least 1 matching profile");
// Do something with the profile.