pub trait PropFetchable: Sized {
type Property: ?Sized;
// Required methods
fn fetch(client: &Client, prop: &Self::Property) -> Result<Self>;
fn a_fetch<'life0, 'async_trait>(
client: &'life0 Client,
prop: &'async_trait Self::Property,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: 'async_trait,
Self::Property: 'async_trait,
'life0: 'async_trait;
}Expand description
A trait representing a type whose instance can be fetched from the API using some property. This is usually the object’s tag.
Required Associated Types§
Required Methods§
Sourcefn fetch(client: &Client, prop: &Self::Property) -> Result<Self>
fn fetch(client: &Client, prop: &Self::Property) -> 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 Player instance from a player tag:
ⓘ
use brawl_api::{Client, Player, traits::*};
let my_client = Client::new("my auth token");
let player = Player::fetch(&my_client, "#PLAYERTAGHERE")?;
// now the data for the given player is available for use
Sourcefn a_fetch<'life0, 'async_trait>(
client: &'life0 Client,
prop: &'async_trait Self::Property,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
Self::Property: 'async_trait,
'life0: 'async_trait,
fn a_fetch<'life0, 'async_trait>(
client: &'life0 Client,
prop: &'async_trait Self::Property,
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
Self::Property: 'async_trait,
'life0: '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 Player instance from a player tag:
ⓘ
use brawl_api::{Client, Player, traits::*};
let my_client = Client::new("my auth token");
let player = Player::a_fetch(&my_client, "#PLAYERTAGHERE").await?;
// now the data for the given player is available for use
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".