pokerust

Crates.iopokerust
lib.rspokerust
version0.3.1
sourcesrc
created_at2020-02-10 22:15:08.020651
updated_at2024-09-17 21:00:01.343684
descriptionPokeapi wrapper
homepagehttps://gitlab.com/lunik1/pokerust
repositoryhttps://gitlab.com/lunik1/pokerust
max_upload_size
id207178
size770,711
(lunik1)

documentation

https://docs.rs/pokerust

README

Pokérust

Crates.io Crates.io Crates.io

Wrapper library for https://pokeapi.co/ v2 with caching support.

Documentation

Documentation for the crate can be found on docs.rs (WIP). For documentation of the API, see https://pokeapi.co/docs/v2.

Basic Usage

Get an object from an API by id

use pokerust::{Berry, FromId};

fn main() {
    let berry = Berry::from_id(1).unwrap();
}

or by name

use pokerust::{Berry, FromName};

fn main() {
    let berry = Berry::from_name("cheri").unwrap();
}

API responses are automatically cached.

You can also fetch the resource lists:

let items = Item::list(5, 20)?;  // ?offset=5&limit=20

// get the lists referenced in the next and previous fields
items.previous_list()?;
items.next_list()?;

// you can also just get the full list
let all_items = Item::full_list()?;

To get resources pointed to by (Named)APIResource, use get():

let berry = Berry::from_name("cheri")?;
let berry_item = berry.item.get()?; // berry_item is an Item

This can be chained:

let marill = PokemonSpecies::from_name("marill")?;
let sea_incense = marill.evolution_chain.get()?.baby_trigger_item.unwrap().get()?;

The location of the pokeapi used can be changed by setting the POKERUST_ENDPOINT environment variable. Defaults to the public instance at https://pokeapi.co/api/v2/. Please consult the pokeapi documentation and read the fair use policy before using the public API instance.

License

This software is licensed under the BSD 3-Clause "New" or "Revised" License.

Commit count: 47

cargo fmt