diff --git a/src/consts/champion.rs b/src/consts/champion.rs
index 510e149..84a83f9 100644
--- a/src/consts/champion.rs
+++ b/src/consts/champion.rs
@@ -8,17 +8,19 @@
use num_enum::{ IntoPrimitive, TryFromPrimitive };
use serde_repr::{ Serialize_repr, Deserialize_repr };
-use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
+use strum_macros::{ EnumString, EnumIter, Display, AsRefStr, IntoStaticStr };
/// League of Legend's champions.
///
/// The documentation of each variant specifies:
/// NAME (`IDENTIFIER`, ID).
+///
+/// Implements [IntoEnumIterator](super::IntoEnumIterator).
#[cfg_attr(feature = "nightly", non_exhaustive)]
#[derive(Debug, Copy, Clone)]
#[derive(IntoPrimitive, TryFromPrimitive)]
#[derive(Serialize_repr, Deserialize_repr)]
-#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
+#[derive(EnumString, EnumIter, Display, AsRefStr, IntoStaticStr)]
#[repr(i16)]
pub enum Champion {
/// A champion that doesn't exist. Used in TeamBans when no champion was banned.
diff --git a/src/consts/division.rs b/src/consts/division.rs
index ea44ab0..c9f1bf6 100644
--- a/src/consts/division.rs
+++ b/src/consts/division.rs
@@ -1,13 +1,16 @@
use std::cmp::Ordering;
+use strum::IntoEnumIterator;
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
use num_enum::{ IntoPrimitive, TryFromPrimitive };
/// LoL and TFT rank divisions, I, II, III, IV, and (deprecated) V.
///
-/// Sorts in reverse numeric order, from low to high rank.
+/// Ordered such that "higher" divisions are greater than "lower" ones: `Division::I > Division::IV`.
///
/// Repr'd as equivalent numeric values, (1, 2, 3, 4, 5).
+///
+/// Implements [IntoEnumIterator](super::IntoEnumIterator). Iterator excludes deprecated `Division::V`.
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
@@ -24,6 +27,16 @@ pub enum Division {
serde_string!(Division);
+/// Returns a DoubleEndedIterator of I, II, III, IV.
+/// Ordered from high rank (I) to low (IV).
+/// Excludes V, which is deprecated.
+impl IntoEnumIterator for Division {
+ type Iterator = std::slice::Iter<'static, Self>;
+ fn iter() -> Self::Iterator {
+ [ Self::I, Self::II, Self::III, Self::IV ].iter()
+ }
+}
+
impl Ord for Division {
fn cmp(&self, other: &Self) -> Ordering {
u8::from(*self).cmp(&u8::from(*other)).reverse()
diff --git a/src/consts/mod.rs b/src/consts/mod.rs
index fb0b694..0bb7e2a 100644
--- a/src/consts/mod.rs
+++ b/src/consts/mod.rs
@@ -1,4 +1,4 @@
-//! Constant data and Enums relevant to the Riot Games API.
+//! Constant data and Enums used with the Riot Games API.
//!
//! This module uses SCREAMING_SNAKE_CASE for enum variants, as enums in this
//! crate should be considered collections of constants.
@@ -29,12 +29,20 @@ pub use queue_type::*;
mod queue;
pub use queue::*;
+pub mod ranks;
+
mod region;
pub use region::*;
mod season;
pub use season::*;
+/// Trait allowing iteration of enum types, implemented by several enums in this module.
+/// Re-exported from strum.
+///
+///
+pub use strum::IntoEnumIterator;
+
mod team;
pub use team::*;
diff --git a/src/consts/ranks.rs b/src/consts/ranks.rs
new file mode 100644
index 0000000..bd64b34
--- /dev/null
+++ b/src/consts/ranks.rs
@@ -0,0 +1,100 @@
+//! Utilities for working with ranks, represented as `(Tier, Division)` tuples.
+
+use std::iter::Peekable;
+
+use strum::IntoEnumIterator;
+
+use super::{ Tier, Division };
+
+/// Iterator for iterating `(Tier, Division)` rank tuples.
+pub struct Iter {
+ tier_iter: Peekable<::Iterator>,
+ div_iter: ::Iterator,
+}
+
+impl Iterator for Iter {
+ type Item = (Tier, Division);
+ fn next(&mut self) -> Option {
+ // First find the tier (innermost loop).
+ // If none found, we go to next tier (in unwrap_or_else case).
+ let div = *self.div_iter.next()
+ .unwrap_or_else(|| {
+ // If no divisions available, go to next tier, reset the divisions, and return I.
+ self.tier_iter.next();
+ self.div_iter = Division::iter();
+ self.div_iter.next().unwrap()
+ });
+
+ // Then find the tier.
+ let tier = *self.tier_iter.peek()?;
+ // If its an apex tier go to next tier and reset the divisions.
+ if tier.is_apex() {
+ self.tier_iter.next();
+ self.div_iter = Division::iter();
+ }
+
+ Some((tier, div))
+ }
+}
+
+/// Returns an iterator over all `(Tier, Division)` pairs, ordered from highest rank to lowest rank.
+///
+/// Apex tiers are all division I, for example: `(Tier::CHALLENGER, Division::I)`.
+/// This matches how they are represented by Riot. There is no "Challenger II", etc.
+pub fn iter() -> Iter {
+ Iter {
+ tier_iter: Tier::iter().peekable(),
+ div_iter: Division::iter(),
+ }
+}
+
+/// Returns an iterator over all `(Tier, Division)` pairs, excluding apex (Master+) tiers,
+/// ordered from highest (Diamond I) to lowest (Iron IV).
+pub fn non_apex_iter() -> Iter {
+ let mut tier_iter = Tier::iter().peekable();
+ while tier_iter.peek().unwrap().is_apex() {
+ tier_iter.next();
+ }
+ Iter {
+ tier_iter: tier_iter,
+ div_iter: Division::iter(),
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{ Tier, Division };
+
+ #[test]
+ fn iter() {
+ let mut it = super::iter();
+ assert_eq!(Some((Tier::CHALLENGER, Division::I)), it.next());
+ assert_eq!(Some((Tier::GRANDMASTER, Division::I)), it.next());
+ assert_eq!(Some((Tier::MASTER, Division::I)), it.next());
+ assert_eq!(Some((Tier::DIAMOND, Division::I)), it.next());
+ assert_eq!(Some((Tier::DIAMOND, Division::II)), it.next());
+ let mut last = None;
+ for next in &mut it {
+ last = Some(next);
+ }
+ assert_eq!(Some((Tier::IRON, Division::IV)), last);
+ assert_eq!(None, it.next());
+ }
+
+
+ #[test]
+ fn non_apex_iter() {
+ let mut it = super::non_apex_iter();
+ assert_eq!(Some((Tier::DIAMOND, Division::I)), it.next());
+ assert_eq!(Some((Tier::DIAMOND, Division::II)), it.next());
+ assert_eq!(Some((Tier::DIAMOND, Division::III)), it.next());
+ assert_eq!(Some((Tier::DIAMOND, Division::IV)), it.next());
+ assert_eq!(Some((Tier::PLATINUM, Division::I)), it.next());
+ let mut last = None;
+ for next in &mut it {
+ last = Some(next);
+ }
+ assert_eq!(Some((Tier::IRON, Division::IV)), last);
+ assert_eq!(None, it.next());
+ }
+}
\ No newline at end of file
diff --git a/src/consts/tier.rs b/src/consts/tier.rs
index 54d55fb..8e3446c 100644
--- a/src/consts/tier.rs
+++ b/src/consts/tier.rs
@@ -1,43 +1,49 @@
use num_enum::{ IntoPrimitive, TryFromPrimitive };
-use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
+use strum_macros::{ EnumString, EnumIter, Display, AsRefStr, IntoStaticStr };
/// LoL and TFT ranked tiers, such as gold, diamond, challenger, etc.
///
/// Sorts from lowest rank to highest rank.
///
-/// Repr'd as arbitrary u8 values.
+/// Repr'd as arbitrary `u8` values.
+///
+/// Implements [IntoEnumIterator](super::IntoEnumIterator).
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(IntoPrimitive, TryFromPrimitive)]
-#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
+#[derive(EnumString, EnumIter, Display, AsRefStr, IntoStaticStr)]
#[repr(u8)]
pub enum Tier {
- IRON = 40,
- BRONZE = 60,
- SILVER = 80,
- GOLD = 100,
- PLATINUM = 120,
- DIAMOND = 140,
- MASTER = 180,
- GRANDMASTER = 200,
+ /// Challenger, the highest tier, an apex tier. Repr: `220_u8`.
CHALLENGER = 220,
+ /// Grand Master, an apex tier. Repr: `200_u8`.
+ GRANDMASTER = 200,
+ /// Master, an apex tier. Repr: `180_u8`.
+ MASTER = 180,
+ /// Diamond, the higest non-apex tier. Repr: `140_u8`.
+ DIAMOND = 140,
+ /// Platinum. Repr: `120_u8`.
+ PLATINUM = 120,
+ /// Gold. Repr: `100_u8`.
+ GOLD = 100,
+ /// Silver. Repr: `80_u8`.
+ SILVER = 80,
+ /// Bronze. Repr: `60_u8`.
+ BRONZE = 60,
+ /// Iron, the lowest tier. Repr: `40_u8`.
+ IRON = 40,
}
serde_string!(Tier);
impl Tier {
- /// If this tier is "standard".
- /// Standard means non-apex (not master+), and not unranked.
+ /// If this tier is an apex tier: master and above.
///
- /// Only these tiers are queryable by LeagueV4Endpoints::get_league_entries(...).
- pub fn is_standard_tier(self) -> bool {
- self < Self::MASTER
- }
-
- /// If this tier is an apex tier.
- /// Master and above.
- pub fn is_apex_tier(self) -> bool {
- Self::MASTER <= self
+ /// Inverse of is_standard().
+ ///
+ /// These tiers are NOT queryable by LeagueV4Endpoints::get_league_entries(...).
+ pub const fn is_apex(self) -> bool {
+ (Self::MASTER as u8) <= (self as u8)
}
}
@@ -50,6 +56,12 @@ mod tests {
assert!(Tier::GOLD < Tier::DIAMOND);
}
+ #[test]
+ fn apex_check() {
+ assert!( Tier::GRANDMASTER.is_apex());
+ assert!(!Tier::DIAMOND.is_apex());
+ }
+
#[test]
fn to_string() {
assert_eq!("GRANDMASTER", Tier::GRANDMASTER.as_ref());
@@ -60,4 +72,20 @@ mod tests {
fn from_string() {
assert_eq!(Ok(Tier::GRANDMASTER), "GRANDMASTER".parse());
}
+
+ #[test]
+ fn iter() {
+ use strum::IntoEnumIterator;
+ let mut iter = Tier::iter();
+ assert_eq!(Some(Tier::CHALLENGER), iter.next());
+ iter.next();
+ iter.next();
+ assert_eq!(Some(Tier::DIAMOND), iter.next());
+ iter.next();
+ iter.next();
+ iter.next();
+ iter.next();
+ assert_eq!(Some(Tier::IRON), iter.next());
+ assert_eq!(None, iter.next());
+ }
}
diff --git a/src/endpoints.rs b/src/endpoints.rs
index c529744..40ebb2a 100644
--- a/src/endpoints.rs
+++ b/src/endpoints.rs
@@ -23,126 +23,160 @@ use crate::consts::Region;
use crate::riot_api::RiotApi;
impl RiotApi {
- /// Handle for ChampionMasteryV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [ChampionMasteryV4](crate::endpoints::ChampionMasteryV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `champion-mastery-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn champion_mastery_v4(&self) -> ChampionMasteryV4 {
ChampionMasteryV4 { base: self }
}
- /// Handle for ChampionV3 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [ChampionV3](crate::endpoints::ChampionV3) endpoints.
+ /// # Riot Developer API Reference
+ /// `champion-v3`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn champion_v3(&self) -> ChampionV3 {
ChampionV3 { base: self }
}
- /// Handle for LeagueExpV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [LeagueExpV4](crate::endpoints::LeagueExpV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `league-exp-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn league_exp_v4(&self) -> LeagueExpV4 {
LeagueExpV4 { base: self }
}
- /// Handle for LeagueV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [LeagueV4](crate::endpoints::LeagueV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `league-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn league_v4(&self) -> LeagueV4 {
LeagueV4 { base: self }
}
- /// Handle for LolStatusV3 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [LolStatusV3](crate::endpoints::LolStatusV3) endpoints.
+ /// # Riot Developer API Reference
+ /// `lol-status-v3`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn lol_status_v3(&self) -> LolStatusV3 {
LolStatusV3 { base: self }
}
- /// Handle for LorRankedV1 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [LorRankedV1](crate::endpoints::LorRankedV1) endpoints.
+ /// # Riot Developer API Reference
+ /// `lor-ranked-v1`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn lor_ranked_v1(&self) -> LorRankedV1 {
LorRankedV1 { base: self }
}
- /// Handle for MatchV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [MatchV4](crate::endpoints::MatchV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `match-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn match_v4(&self) -> MatchV4 {
MatchV4 { base: self }
}
- /// Handle for SpectatorV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [SpectatorV4](crate::endpoints::SpectatorV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `spectator-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn spectator_v4(&self) -> SpectatorV4 {
SpectatorV4 { base: self }
}
- /// Handle for SummonerV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [SummonerV4](crate::endpoints::SummonerV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `summoner-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn summoner_v4(&self) -> SummonerV4 {
SummonerV4 { base: self }
}
- /// Handle for TftLeagueV1 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [TftLeagueV1](crate::endpoints::TftLeagueV1) endpoints.
+ /// # Riot Developer API Reference
+ /// `tft-league-v1`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn tft_league_v1(&self) -> TftLeagueV1 {
TftLeagueV1 { base: self }
}
- /// Handle for TftMatchV1 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [TftMatchV1](crate::endpoints::TftMatchV1) endpoints.
+ /// # Riot Developer API Reference
+ /// `tft-match-v1`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn tft_match_v1(&self) -> TftMatchV1 {
TftMatchV1 { base: self }
}
- /// Handle for TftSummonerV1 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [TftSummonerV1](crate::endpoints::TftSummonerV1) endpoints.
+ /// # Riot Developer API Reference
+ /// `tft-summoner-v1`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn tft_summoner_v1(&self) -> TftSummonerV1 {
TftSummonerV1 { base: self }
}
- /// Handle for ThirdPartyCodeV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [ThirdPartyCodeV4](crate::endpoints::ThirdPartyCodeV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `third-party-code-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn third_party_code_v4(&self) -> ThirdPartyCodeV4 {
ThirdPartyCodeV4 { base: self }
}
- /// Handle for TournamentStubV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [TournamentStubV4](crate::endpoints::TournamentStubV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `tournament-stub-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn tournament_stub_v4(&self) -> TournamentStubV4 {
TournamentStubV4 { base: self }
}
- /// Handle for TournamentV4 endpoints. This method is automatically generated.
+ /// Returns a handle for accessing [TournamentV4](crate::endpoints::TournamentV4) endpoints.
+ /// # Riot Developer API Reference
+ /// `tournament-v4`
///
- /// Official API Reference
+ /// Note: this method is automatically generated.
#[inline]
pub fn tournament_v4(&self) -> TournamentV4 {
TournamentV4 { base: self }
}
}
-/// ChampionMasteryV4 endpoints. This struct is automatically generated.
+/// ChampionMasteryV4 endpoints handle, accessed by calling [`champion_mastery_v4()`](crate::RiotApi::champion_mastery_v4) on a [`RiotApi`](crate::RiotApi) instance.
+/// # Riot Developer API Reference
+/// `champion-mastery-v4`
///
-/// Official API Reference
+/// Note: this struct is automatically generated.
pub struct ChampionMasteryV4<'a> {
base: &'a RiotApi,
}
impl<'a> ChampionMasteryV4<'a> {
/// Get all champion mastery entries sorted by number of champion points descending,
- ///
- /// Official API Reference
/// # Parameters
/// * `region` - Region to query.
/// * `encryptedSummonerId` - Summoner ID associated with the player
+ /// # Riot Developer API Reference
+ /// `champion-mastery-v4.getAllChampionMasteries`
+ ///
+ /// Note: this method is automatically generated.
pub fn get_all_champion_masteries(&self, region: Region, encrypted_summoner_id: &str)
-> impl Future