[][src]Trait brawl_api::traits::FetchFrom

pub trait FetchFrom<T>: Sized {
    fn fetch_from(client: &Client, value: &T) -> Result<Self>;
fn a_fetch_from<'life0, 'life1, 'async_trait>(
        client: &'life0 Client,
        value: &'life1 T
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        Self: 'async_trait
; }

A trait indicating that another type can be converted into this one by fetching from the API. Note that, thanks to a blanket implementation, implementing this implies implementing FetchInto for the other type.

Required methods

fn fetch_from(client: &Client, value: &T) -> Result<Self>

(Sync) Attempts to request to the API and return a new instance of the type being turned into.

Errors

See the respective struct's fetch implementation (or PropFetchable/PropLimFetchable implementation).

Examples

This example is not tested
use brawl_api::{Client, Player, Club, traits::*};

let my_client = Client::new("my auth token");
let club = Club::fetch(&my_client, "#CLUB_TAG_HERE")?;
let some_member = &club.members[0];
let some_player = Player::fetch_from(&my_client, some_member)?;
// now `some_member`'s full data, as a Player, is available for use.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    value: &'life1 T
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: 'async_trait, 

(Async) Attempts to request to the API and return a new instance of the type being turned into.

Errors

See the respective struct's a_fetch implementation (or PropFetchable/PropLimFetchable implementation).

Examples

This example is not tested
use brawl_api::{Client, Player, Club, traits::*};

let my_client = Client::new("my auth token");
let club = Club::a_fetch(&my_client, "#CLUB_TAG_HERE").await?;
let some_member = &club.members[0];
let some_player = Player::a_fetch_from(&my_client, some_member).await?;
// now `some_member`'s full data, as a Player, is available for use.
Loading content...

Implementors

impl FetchFrom<Brawlers> for Brawler[src]

fn fetch_from(client: &Client, b_brawler: &Brawlers) -> Result<Brawler>[src]

(Sync) Attempts to fetch a Brawler from an existing Brawlers variant.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    b_brawler: &'life1 Brawlers
) -> Pin<Box<dyn Future<Output = Result<Brawler>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Attempts to fetch a Brawler from an existing Brawlers variant.

impl FetchFrom<ClubMember> for Player[src]

fn fetch_from(client: &Client, member: &ClubMember) -> Result<Player>[src]

(Sync) Fetches a Player instance, given a preexisting ClubMember instance.

Errors

See Player::fetch.

Examples

This example is not tested
use brawl_api::{Client, Player, Club, traits::*};

let my_client = Client::new("my auth token");
let club = Club::fetch(&my_client, "#CLUB_TAG_HERE")?;
let some_member = &club.members[0];
let some_player = Player::fetch_from(&my_client, some_member)?;
// now `some_member`'s full data, as a Player, is available for use.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    member: &'life1 ClubMember
) -> Pin<Box<dyn Future<Output = Result<Player>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a Player instance, given a preexisting ClubMember instance.

Errors

See Player::fetch.

Examples

This example is not tested
use brawl_api::{Client, Player, Club, traits::*};

let my_client = Client::new("my auth token");
let club = Club::a_fetch(&my_client, "#CLUB_TAG_HERE").await?;
let some_member = &club.members[0];
let some_player = Player::a_fetch_from(&my_client, some_member).await?;
// now `some_member`'s full data, as a Player, is available for use.

impl FetchFrom<BattleBrawler> for Brawler[src]

fn fetch_from(client: &Client, b_brawler: &BattleBrawler) -> Result<Brawler>[src]

(Sync) Attempts to fetch a Brawler from an existing BattleBrawler instance.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    b_brawler: &'life1 BattleBrawler
) -> Pin<Box<dyn Future<Output = Result<Brawler>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Attempts to fetch a Brawler from an existing BattleBrawler instance.

impl FetchFrom<BattlePlayer> for Player[src]

fn fetch_from(client: &Client, b_player: &BattlePlayer) -> Result<Player>[src]

(Async) Fetches a Player instance, given a preexisting BattlePlayer instance.

Errors

See Player::fetch.

Examples

This example is not tested
use brawl_api::{
    Client, Player, BattleLog, Battle, BattleResultInfo, BattlePlayer,
    traits::*
};

let my_client = Client::new("my auth token");
let battlelog = BattleLog::fetch(&my_client, "#PLAYER_TAG_HERE")?;
let most_recent_battle: Option<&Battle> = battlelog.get(0);

if let Some(battle) = most_recent_battle {
    if let Some(ref teams) = &battle.result.teams {
        let some_b_player: &BattlePlayer = &teams[0][0];
        let some_player = Player::fetch_from(&my_client, some_b_player)?;
        // now `some_b_player`'s full data, as a Player, is available for use.
    }
}

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    b_player: &'life1 BattlePlayer
) -> Pin<Box<dyn Future<Output = Result<Player>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a Player instance, given a preexisting BattlePlayer instance.

Errors

See Player::fetch.

Examples

This example is not tested
use brawl_api::{
    Client, Player, BattleLog, Battle, BattleResultInfo, BattlePlayer,
    traits::*
};

let my_client = Client::new("my auth token");
let battlelog = BattleLog::a_fetch(&my_client, "#PLAYER_TAG_HERE").await?;
let most_recent_battle: Option<&Battle> = battlelog.get(0);

if let Some(battle) = most_recent_battle {
    if let Some(ref teams) = &battle.result.teams {
        let some_b_player: &BattlePlayer = &teams[0][0];
        let some_player = Player::a_fetch_from(&my_client, some_b_player).await?;
        // now `some_b_player`'s full data, as a Player, is available for use.
    }
}

impl FetchFrom<Player> for BattleLog[src]

fn fetch_from(client: &Client, player: &Player) -> Result<BattleLog>[src]

(Sync) Fetches a given player's battlelog (a BattleLog instance) by using data from an existing Player instance. (See BattleLog::fetch for more details.)

Note that this is simply to minimize efforts when a player was already fetched. If no Player instance was previously present, it is recommended to simply BattleLog::fetch with the specific player's tag.

Examples

This example is not tested
use brawl_api::{Client, Player, BattleLog, traits::*};

let my_client = Client::new("my auth token");
let player = Player::fetch(&my_client, "#PLAYERTAGHERE")?;
// do stuff with player...
let player_battlelog = BattleLog::fetch_from(&my_client, &player)?;
// now the player's battlelog is available for use

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    player: &'life1 Player
) -> Pin<Box<dyn Future<Output = Result<BattleLog>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a given player's battlelog (a BattleLog instance) by using data from an existing Player instance. (See BattleLog::fetch for more details.)

Note that this is simply to minimize efforts when a player was already fetched. If no Player instance was previously present, it is recommended to simply BattleLog::fetch with the specific player's tag.

Examples

This example is not tested
use brawl_api::{Client, Player, BattleLog, traits::*};

let my_client = Client::new("my auth token");
let player = Player::a_fetch(&my_client, "#PLAYERTAGHERE").await?;
// do stuff with player...
let player_battlelog = BattleLog::a_fetch_from(&my_client, &player).await?;
// now the player's battlelog is available for use

impl FetchFrom<PlayerBrawlerStat> for Brawler[src]

fn fetch_from(client: &Client, p_brawler: &PlayerBrawlerStat) -> Result<Brawler>[src]

(Sync) Attempts to fetch a Brawler from an existing PlayerBrawlerStat instance.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    p_brawler: &'life1 PlayerBrawlerStat
) -> Pin<Box<dyn Future<Output = Result<Brawler>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Attempts to fetch a Brawler from an existing PlayerBrawlerStat instance.

impl FetchFrom<PlayerClub> for Club[src]

fn fetch_from(client: &Client, p_club: &PlayerClub) -> Result<Club>[src]

(Sync) Fetches a Club using data from a PlayerClub object.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    p_club: &'life1 PlayerClub
) -> Pin<Box<dyn Future<Output = Result<Club>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a Club using data from a PlayerClub object.

impl FetchFrom<ClubRanking> for Club[src]

fn fetch_from(client: &Client, c_ranking: &ClubRanking) -> Result<Club>[src]

(Sync) Fetches a Club using data from a ClubRanking object.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    c_ranking: &'life1 ClubRanking
) -> Pin<Box<dyn Future<Output = Result<Club>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a Club using data from a ClubRanking object.

impl FetchFrom<PlayerRanking> for Player[src]

fn fetch_from(client: &Client, p_ranking: &PlayerRanking) -> Result<Player>[src]

(Sync) Fetches a Player using data from a PlayerRanking object.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    client: &'life0 Client,
    p_ranking: &'life1 PlayerRanking
) -> Pin<Box<dyn Future<Output = Result<Player>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait, 
[src]

(Async) Fetches a Player using data from a PlayerRanking object.

impl<T: Sync + Send + Clone> FetchFrom<T> for T[src]

fn fetch_from(_: &Client, t: &T) -> Result<T>[src]

(Sync) Returns a copy of the current instance when attempting to fetch from itself. In order to re-fetch, see Refetchable.

Errors

Never errors; is only a Result in order to match the trait signature.

fn a_fetch_from<'life0, 'life1, 'async_trait>(
    __arg0: &'life0 Client,
    t: &'life1 T
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait,
    Self: 'async_trait, 
[src]

(Async) Returns a copy of the current instance when attempting to fetch from itself. In order to re-fetch, see Refetchable.

Errors

Never errors; is only a Result in order to match the trait signature.

Loading content...