Add division enum, update enums with strum macros, serde_repr

pull/5/head
Mingwei Samuel 2019-10-25 13:37:23 -07:00
parent 42c6801453
commit 44b12c2f32
6 changed files with 73 additions and 21 deletions

View File

@ -18,6 +18,9 @@ parking_lot = { version = "0.9", features = [ "nightly" ] }
reqwest = { version = "0.10.0-alpha.1", features = [ "gzip", "json" ] }
scan_fmt = "0.2"
serde = { version = "1.0", features = [ "derive" ] }
serde_repr = "0.1"
strum = "0.16"
strum_macros = "0.16"
tokio-timer = "0.3.0-alpha.5"
url = "2.1"

19
src/consts/division.rs Normal file
View File

@ -0,0 +1,19 @@
#![allow(deprecated)]
use std::fmt::Debug;
use strum_macros::{ EnumString, Display, AsRefStr };
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
#[derive(EnumString, Display, AsRefStr)]
#[repr(u8)]
pub enum Division {
I = 1,
II = 2,
III = 3,
IV = 4,
#[deprecated(note="Removed for 2019.")]
V = 5,
}

View File

@ -1,19 +1,22 @@
//! Constant data and Enums relevant to the Riot Games API.
mod region;
pub use region::*;
mod champion;
pub use champion::*;
mod season;
pub use season::*;
mod queue;
pub use queue::*;
mod division;
pub use division::*;
mod queue_type;
pub use queue_type::*;
mod queue;
pub use queue::*;
mod region;
pub use region::*;
mod season;
pub use season::*;
mod team;
pub use team::*;

View File

@ -1,7 +1,14 @@
// This file is automatically generated.
// Do not directly edit.
#![allow(deprecated)]
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends matchmaking queue.
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u16)]
pub enum Queue {
/// Custom games.

View File

@ -1,28 +1,41 @@
use std::fmt;
use std::fmt::Debug;
#[derive(fmt::Debug, Copy, Clone)]
use strum_macros::{ EnumString, Display, AsRefStr };
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq, Hash)]
#[derive(EnumString, Display, AsRefStr)]
pub enum QueueType {
// League of Legends, Summoner's Rift (5v5), Ranked Solo Queue.
#[strum(to_string="RANKED_SOLO_5x5")]
RankedSolo5x5,
// League of Legends, Summoner's Rift (5v5), Flex Queue.
#[strum(to_string="RANKED_FLEX_SR")]
RankedFlexSr,
// League of Legends, Twisted Treeline (3v3), Flex Queue.
#[strum(to_string="RANKED_FLEX_TT")]
RankedFlexTt,
// Ranked Teamfight Tactics.
#[strum(to_string="RANKED_TFT")]
RankedTft,
}
impl QueueType {
const NAMES: [&'static str; 4] = [
"RANKED_SOLO_5x5",
"RANKED_FLEX_SR",
"RANKED_FLEX_TT",
"RANKED_TFT",
];
}
#[cfg(test)]
mod test {
use super::*;
impl fmt::Display for QueueType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", Self::NAMES[*self as usize])
#[test]
fn check_as_ref() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RankedSolo5x5.as_ref());
}
#[test]
fn check_to_string() {
assert_eq!("RANKED_SOLO_5x5", QueueType::RankedSolo5x5.to_string());
}
#[test]
fn check_from_string() {
assert_eq!(Some(QueueType::RankedSolo5x5), "RANKED_SOLO_5x5".parse().ok());
}
}

View File

@ -8,8 +8,15 @@
return name;
});
}}{{= dotUtils.preamble() }}
#![allow(deprecated)]
use serde_repr::{ Serialize_repr, Deserialize_repr };
/// League of Legends matchmaking queue.
#[derive(Debug, Copy, Clone)]
#[derive(Eq, PartialEq)]
#[derive(Serialize_repr, Deserialize_repr)]
#[repr(u16)]
pub enum Queue {
{{
for (let [ groupName, colQueues ] of groupedQueues) {