pokemon_rs/lib.rs
1#![deny(
2 unused_import_braces,
3 unused_imports,
4 unused_variables,
5 unused_allocation,
6 unused_crate_dependencies,
7 unused_extern_crates
8)]
9#![allow(dead_code, non_upper_case_globals)]
10
11mod github {
12 pub mod constants;
13}
14mod data;
15mod declarations;
16mod functions;
17mod generation;
18mod list;
19mod util;
20
21/// Returns a list of all Pokémons from all generations
22///
23/// # Arguments
24/// `locale` - `Option<&str>` that holds the language
25/// you would like the Pokémon names should be translated in
26///
27/// # Example
28/// ```rs
29/// default language is english so providing None is the same as providing `Some("en")`
30/// pokemon_rs::get_all(None);
31/// pokemon_rs::get_all(Some("jp"));
32/// ```
33pub fn get_all(locale: Option<&str>) -> Vec<&str> {
34 functions::get_all(locale)
35}
36/// Returns the Pokémon as a &str that corresponds given id
37///
38/// # Arguments
39/// `id` - `usize` that represents the official Pokémon id, used find the correct Pokémon
40/// `locale` - `Option<&str>` that holds the language
41///
42/// # Example
43/// ```rs
44/// // default language is english so providing None is the same as providing `Some("en")`
45/// pokemon_rs::get_by_id(1, Some("jp"));
46/// pokemon_rs::get_by_id(24, None);
47/// ```
48pub fn get_by_id(id: usize, locale: Option<&str>) -> &str {
49 functions::get_by_id(id, locale).unwrap()
50}
51/// Returns the Pokémon's id that corresponds to a given id
52///
53/// # Arguments
54///
55/// `name` - `&str` that represents the Pokémon you'd like to lookup id for.
56/// `locale` - `Option<&str>` that holds the language you are searching for Pokémon id in.
57///
58/// # Example
59/// ```rs
60/// // default language is english so providing None is the same as providing `Some("en")`
61/// pokemon_rs::get_id_by_name("Pikachu", None);
62/// pokemon_rs::get_id_by_name("フシギダネ", Some("jp"));
63/// ```
64///
65pub fn get_id_by_name(name: &str, locale: Option<&str>) -> usize {
66 functions::get_id_by_name(name, locale)
67}
68/// Returns a random Pokémon out of all Pokémon released to this day
69///
70/// # Arguments
71///
72/// `locale` - `Option<&str>` that holds the language
73///
74/// # Example
75/// ```rs
76/// // default language is english so providing None is the same as providing `Some("en")`
77/// pokemon_rs::random(None);
78/// pokemon_rs::random(Some("jp"));
79/// ```
80pub fn random(locale: Option<&str>) -> String {
81 functions::random(locale).unwrap()
82}
83/// Returns a whole generation as a sorted `Vector<&str>` based on its given region name
84///
85/// # Arguments
86///
87/// `generation` - `&str` that represents the generation (or region) name you would like to get.
88/// `locale` - `Option<&str>` that represents which language you would like the Pokémon names in returned generation in.
89///
90/// # Example
91/// ```rs
92/// // default language is english so providing None is the same as providing `Some("en")`
93/// pokemon_rs::get_generation("Kanto", None);
94/// pokemon_rs::get_generation("Kanto", Some("jp"));
95/// ```
96pub fn get_generation<'a>(generation: &str, locale: Option<&'a str>) -> Vec<&'a str> {
97 functions::get_complete_generation(generation, locale)
98}
99/// Returns region name from generation number in released order.
100/// Kanto = 1, Johto = 2, Hoenn = 3 ...
101///
102/// # Arguments
103///
104/// `generation_number` - `usize`
105/// `locale` - `Option<&str>` that represents which language you would like the Pokémon names in returned generation in.
106///
107/// # Example
108/// ```rs
109/// pokemon_rs::get_region(1, Some("en"));
110/// let paldea: String = pokemon_rs::get_region(9, Some("en"));
111/// ```
112pub fn get_region(generation_number: usize, locale: Option<&str>) -> String {
113 functions::get_region_by_generation(generation_number, locale)
114}
115/// Returns all region names
116///
117/// # Arguments
118///
119/// `locale` - `Option<&str>` that represents which language you would like the Pokémon names in returned generation in.
120///
121/// # Example
122/// ```rs
123/// let all_regions: Vec<String> = pokemon_rs::get_all_regions(Some("en"));
124/// ```
125pub fn get_all_regions(locale: Option<&str>) -> Vec<String> {
126 functions::get_all_regions(locale)
127}
128/// Returns all Pokemon element types
129///
130/// # Arguments
131///
132/// `locale` - `Option<&str>` that represents which language you would like the Pokémon element types in returned generation in.
133/// NB: The lib in it current state only supports element types in english (default locale) asking for other locales will create a panic
134/// # Example
135/// ```rs
136/// let all_regions: Vec<String> = pokemon_rs::get_all_types(Some("en"));
137/// ```
138pub fn get_all_types(locale: Option<&str>) -> Vec<String> {
139 functions::get_all_types(locale)
140}
141/// Returns specific Pokemon element type by id and locale
142///
143/// # Arguments
144///
145/// `locale` - `Option<&str>` that represents which language you would like the Pokémon element types in returned generation in.
146/// NB: The lib in it current state only supports element types in english (default locale) asking for other locales will create a panic
147/// # Example
148/// ```rs
149/// let all_regions: Vec<String> = pokemon_rs::get_type_by_id(1, Some("en"));
150/// ```
151pub fn get_type_by_id(id: usize, locale: Option<&str>) -> String {
152 functions::get_type_by_id(id, locale)
153}
154/// Returns a ANSI escape-sequence-based sprite represented as a String of a Pokemon by name
155///
156/// # Arguments
157///
158/// `name` - `&str` that represents the name of the pokemon you wish to get a sprite for.
159///
160/// # Example
161/// ```rs
162/// let bulbasaur_sprite: Result<String, std::io::Error> = get_sprite_by_name("bulbasaur");
163/// ```
164pub fn get_sprite_by_name(name: &str) -> Result<String, std::io::Error> {
165 functions::get_sprite_by_name(name)
166}
167/// Returns a ANSI escape-sequence-based sprite represented as a String of a Pokemon by id
168///
169/// # Arguments
170///
171/// `id` - `usize` that represents the id of the pokemon you wish to get a sprite for.
172///
173/// # Example
174/// ```rs
175/// let ivysaur_sprite: Result<String, std::io::Error> = get_sprite_by_id(2);
176/// ```
177pub fn get_sprite_by_id(id: usize) -> Result<String, std::io::Error> {
178 functions::get_sprite_by_id(id)
179}
180
181#[cfg(test)]
182mod test;