Convert Season from enum into newtype_enum

This commit is contained in:
Mingwei Samuel 2021-06-30 19:46:26 -07:00
parent 35f826b198
commit 4b23f9afed
2 changed files with 45 additions and 2 deletions

View file

@ -6,6 +6,30 @@
// // // //
/////////////////////////////////////////////// ///////////////////////////////////////////////
newtype_enum! {
/// A League of Legends season for competitive matchmaking.
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub newtype_enum Season {
PRESEASON_3 = 0,
SEASON_3 = 1,
PRESEASON_2014 = 2,
SEASON_2014 = 3,
PRESEASON_2015 = 4,
SEASON_2015 = 5,
PRESEASON_2016 = 6,
SEASON_2016 = 7,
PRESEASON_2017 = 8,
SEASON_2017 = 9,
PRESEASON_2018 = 10,
SEASON_2018 = 11,
PRESEASON_2019 = 12,
SEASON_2019 = 13,
PRESEASON_2020 = 14,
SEASON_2020 = 15,
}
}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
@ -16,7 +40,7 @@ use num_enum::{ IntoPrimitive, TryFromPrimitive };
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season2 {
PRESEASON_3 = 0, PRESEASON_3 = 0,
SEASON_3 = 1, SEASON_3 = 1,
PRESEASON_2014 = 2, PRESEASON_2014 = 2,

View file

@ -3,6 +3,25 @@
const seasons = require('./.seasons.json'); const seasons = require('./.seasons.json');
}}{{= dotUtils.preamble() }} }}{{= dotUtils.preamble() }}
newtype_enum! {
/// A League of Legends season for competitive matchmaking.
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub newtype_enum Season {
{{
for (const e of seasons) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];
}}
{{~ desc :line }}
/// {{= line }}
{{~}}
{{= e['x-name'] }} = {{= e['x-value'] }},
{{
}
}}
}
}
use serde_repr::{ Serialize_repr, Deserialize_repr }; use serde_repr::{ Serialize_repr, Deserialize_repr };
use num_enum::{ IntoPrimitive, TryFromPrimitive }; use num_enum::{ IntoPrimitive, TryFromPrimitive };
@ -13,7 +32,7 @@ use num_enum::{ IntoPrimitive, TryFromPrimitive };
#[derive(Serialize_repr, Deserialize_repr)] #[derive(Serialize_repr, Deserialize_repr)]
#[derive(IntoPrimitive, TryFromPrimitive)] #[derive(IntoPrimitive, TryFromPrimitive)]
#[repr(u8)] #[repr(u8)]
pub enum Season { pub enum Season2 {
{{ {{
for (const e of seasons) { for (const e of seasons) {
const desc = e['x-desc'] ? e['x-desc'].split('\n') : []; const desc = e['x-desc'] ? e['x-desc'].split('\n') : [];