pub trait PropLimFetchable: Sized {
type Property: ?Sized;
type Limit: PrimInt;
// Required methods
fn fetch(
client: &Client,
prop: &Self::Property,
limit: Self::Limit,
) -> Result<Self>;
fn a_fetch<'life0, 'async_trait>(
client: &'life0 Client,
prop: &'async_trait Self::Property,
limit: Self::Limit,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait,
Self::Property: 'async_trait,
Self::Limit: 'async_trait,
'life0: 'async_trait;
}Expand description
A trait representing a type whose instance can be fetched from the API using some property and specifying a limit of how many objects to fetch.
Note: types which simply require the limit for fetching use PropFetchable instead
(with the limit being the property itself).
Required Associated Types§
Required Methods§
Sourcefn fetch(
client: &Client,
prop: &Self::Property,
limit: Self::Limit,
) -> Result<Self>
fn fetch( client: &Client, prop: &Self::Property, limit: Self::Limit, ) -> Result<Self>
(Sync) Fetch and construct a new instance of this type.
§Errors
This function may error:
- While requesting (will return an
Error::Request); - After receiving a bad status code (API or other error - returns an
Error::Status); - After a ratelimit is indicated by the API, while also specifying when it is lifted (
Error::Ratelimited); - While parsing incoming JSON (will return an
Error::Json).
(All of those, of course, wrapped inside an Err.)
§Examples
Fetching a world-wide player leaderboard (PlayerLeaderboard):
use brawl_api::{PlayerLeaderboard, Client, traits::PropLimFetchable};
let client = Client::new("my auth key");
// if the fetch is successful, then the variable below will have the global top 100 players
// in the 'items' field (i.e. '*top100players').
let top100players: PlayerLeaderboard = PlayerLeaderboard::fetch(&client, "global", 100)?;
// get player ranked #1. The items are usually sorted (i.e. rank 1 on index [0], rank 2
// on index [1] etc.), but, to make the program absolutely safe, might want to .sort()
let player1 = &top100players[0];
assert_eq!(player1.rank, 1);
Sourcefn a_fetch<'life0, 'async_trait>(
client: &'life0 Client,
prop: &'async_trait Self::Property,
limit: Self::Limit,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
fn a_fetch<'life0, 'async_trait>( client: &'life0 Client, prop: &'async_trait Self::Property, limit: Self::Limit, ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
(Async) Fetch and construct a new instance of this type.
§Errors
This function may error:
- While requesting (will return an
Error::Request); - After receiving a bad status code (API or other error - returns an
Error::Status); - After a ratelimit is indicated by the API, while also specifying when it is lifted (
Error::Ratelimited); - While parsing incoming JSON (will return an
Error::Json).
(All of those, of course, wrapped inside an Err.)
§Examples
Fetching a world-wide player leaderboard (PlayerLeaderboard):
use brawl_api::{PlayerLeaderboard, Client, traits::PropLimFetchable};
let client = Client::new("my auth key");
// if the fetch is successful, then the variable below will have the global top 100 players
// in the 'items' field (i.e. '*top100players').
let top100players: PlayerLeaderboard = PlayerLeaderboard::a_fetch(&client, "global", 100).await?;
// get player ranked #1. The items are usually sorted (i.e. rank 1 on index [0], rank 2
// on index [1] etc.), but, to make the program absolutely safe, might want to .sort()
let player1 = &top100players[0];
assert_eq!(player1.rank, 1);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.