Add macro to create newtype_enums

This commit is contained in:
Mingwei Samuel 2021-06-30 18:50:08 -07:00
parent 07348a5c53
commit 5daeab990a
5 changed files with 459 additions and 485 deletions

View file

@ -8,364 +8,332 @@
use serde::{ Serialize, Deserialize }; use serde::{ Serialize, Deserialize };
/// League of Legends champions. newtype_enum! {
/// /// A League of Legends champion.
/// The documentation of each const field specifies:<br> ///
/// NAME (`IDENTIFIER`, ID). /// This newtype acts as a C-like enum; each variant corresponds to an
/// /// integer value. Using a newtype allows _unknown_ variants to be
/// Implements [IntoEnumIterator](super::IntoEnumIterator). /// represented. This is important when Riot adds new champions.
#[derive(Serialize, Deserialize)] ///
#[derive(Copy, Clone)] /// Field | Name | Identifier | Id
#[derive(PartialEq, Eq, PartialOrd, Ord)] /// ---|---|---|---
#[serde(transparent)] /// `AATROX` | "Aatrox" | "Aatrox" | 266
#[repr(transparent)] /// `AHRI` | "Ahri" | "Ahri" | 103
pub struct Champion(pub i16); /// `AKALI` | "Akali" | "Akali" | 84
/// `ALISTAR` | "Alistar" | "Alistar" | 12
impl Champion { /// `AMUMU` | "Amumu" | "Amumu" | 32
/** Aatrox (`Aatrox`, 266) */ pub const AATROX: Self = Self(266); /// `ANIVIA` | "Anivia" | "Anivia" | 34
/** Ahri (`Ahri`, 103) */ pub const AHRI: Self = Self(103); /// `ANNIE` | "Annie" | "Annie" | 1
/** Akali (`Akali`, 84) */ pub const AKALI: Self = Self(84); /// `APHELIOS` | "Aphelios" | "Aphelios" | 523
/** Alistar (`Alistar`, 12) */ pub const ALISTAR: Self = Self(12); /// `ASHE` | "Ashe" | "Ashe" | 22
/** Amumu (`Amumu`, 32) */ pub const AMUMU: Self = Self(32); /// `AURELION_SOL` | "Aurelion Sol" | "AurelionSol" | 136
/** Anivia (`Anivia`, 34) */ pub const ANIVIA: Self = Self(34); /// `AZIR` | "Azir" | "Azir" | 268
/** Annie (`Annie`, 1) */ pub const ANNIE: Self = Self(1); /// `BARD` | "Bard" | "Bard" | 432
/** Aphelios (`Aphelios`, 523) */ pub const APHELIOS: Self = Self(523); /// `BLITZCRANK` | "Blitzcrank" | "Blitzcrank" | 53
/** Ashe (`Ashe`, 22) */ pub const ASHE: Self = Self(22); /// `BRAND` | "Brand" | "Brand" | 63
/** Aurelion Sol (`AurelionSol`, 136) */ pub const AURELION_SOL: Self = Self(136); /// `BRAUM` | "Braum" | "Braum" | 201
/** Azir (`Azir`, 268) */ pub const AZIR: Self = Self(268); /// `CAITLYN` | "Caitlyn" | "Caitlyn" | 51
/** Bard (`Bard`, 432) */ pub const BARD: Self = Self(432); /// `CAMILLE` | "Camille" | "Camille" | 164
/** Blitzcrank (`Blitzcrank`, 53) */ pub const BLITZCRANK: Self = Self(53); /// `CASSIOPEIA` | "Cassiopeia" | "Cassiopeia" | 69
/** Brand (`Brand`, 63) */ pub const BRAND: Self = Self(63); /// `CHO_GATH` | "Cho'Gath" | "Chogath" | 31
/** Braum (`Braum`, 201) */ pub const BRAUM: Self = Self(201); /// `CORKI` | "Corki" | "Corki" | 42
/** Caitlyn (`Caitlyn`, 51) */ pub const CAITLYN: Self = Self(51); /// `DARIUS` | "Darius" | "Darius" | 122
/** Camille (`Camille`, 164) */ pub const CAMILLE: Self = Self(164); /// `DIANA` | "Diana" | "Diana" | 131
/** Cassiopeia (`Cassiopeia`, 69) */ pub const CASSIOPEIA: Self = Self(69); /// `DR_MUNDO` | "Dr. Mundo" | "DrMundo" | 36
/** Cho'Gath (`Chogath`, 31) */ pub const CHO_GATH: Self = Self(31); /// `DRAVEN` | "Draven" | "Draven" | 119
/** Corki (`Corki`, 42) */ pub const CORKI: Self = Self(42); /// `EKKO` | "Ekko" | "Ekko" | 245
/** Darius (`Darius`, 122) */ pub const DARIUS: Self = Self(122); /// `ELISE` | "Elise" | "Elise" | 60
/** Diana (`Diana`, 131) */ pub const DIANA: Self = Self(131); /// `EVELYNN` | "Evelynn" | "Evelynn" | 28
/** Dr. Mundo (`DrMundo`, 36) */ pub const DR_MUNDO: Self = Self(36); /// `EZREAL` | "Ezreal" | "Ezreal" | 81
/** Draven (`Draven`, 119) */ pub const DRAVEN: Self = Self(119); /// `FIDDLESTICKS` | "Fiddlesticks" | "FiddleSticks" | 9
/** Ekko (`Ekko`, 245) */ pub const EKKO: Self = Self(245); /// `FIORA` | "Fiora" | "Fiora" | 114
/** Elise (`Elise`, 60) */ pub const ELISE: Self = Self(60); /// `FIZZ` | "Fizz" | "Fizz" | 105
/** Evelynn (`Evelynn`, 28) */ pub const EVELYNN: Self = Self(28); /// `GALIO` | "Galio" | "Galio" | 3
/** Ezreal (`Ezreal`, 81) */ pub const EZREAL: Self = Self(81); /// `GANGPLANK` | "Gangplank" | "Gangplank" | 41
/** Fiddlesticks (`FiddleSticks`, 9) */ pub const FIDDLESTICKS: Self = Self(9); /// `GAREN` | "Garen" | "Garen" | 86
/** Fiora (`Fiora`, 114) */ pub const FIORA: Self = Self(114); /// `GNAR` | "Gnar" | "Gnar" | 150
/** Fizz (`Fizz`, 105) */ pub const FIZZ: Self = Self(105); /// `GRAGAS` | "Gragas" | "Gragas" | 79
/** Galio (`Galio`, 3) */ pub const GALIO: Self = Self(3); /// `GRAVES` | "Graves" | "Graves" | 104
/** Gangplank (`Gangplank`, 41) */ pub const GANGPLANK: Self = Self(41); /// `GWEN` | "Gwen" | "Gwen" | 887
/** Garen (`Garen`, 86) */ pub const GAREN: Self = Self(86); /// `HECARIM` | "Hecarim" | "Hecarim" | 120
/** Gnar (`Gnar`, 150) */ pub const GNAR: Self = Self(150); /// `HEIMERDINGER` | "Heimerdinger" | "Heimerdinger" | 74
/** Gragas (`Gragas`, 79) */ pub const GRAGAS: Self = Self(79); /// `ILLAOI` | "Illaoi" | "Illaoi" | 420
/** Graves (`Graves`, 104) */ pub const GRAVES: Self = Self(104); /// `IRELIA` | "Irelia" | "Irelia" | 39
/** Gwen (`Gwen`, 887) */ pub const GWEN: Self = Self(887); /// `IVERN` | "Ivern" | "Ivern" | 427
/** Hecarim (`Hecarim`, 120) */ pub const HECARIM: Self = Self(120); /// `JANNA` | "Janna" | "Janna" | 40
/** Heimerdinger (`Heimerdinger`, 74) */ pub const HEIMERDINGER: Self = Self(74); /// `JARVAN_IV` | "Jarvan IV" | "JarvanIV" | 59
/** Illaoi (`Illaoi`, 420) */ pub const ILLAOI: Self = Self(420); /// `JAX` | "Jax" | "Jax" | 24
/** Irelia (`Irelia`, 39) */ pub const IRELIA: Self = Self(39); /// `JAYCE` | "Jayce" | "Jayce" | 126
/** Ivern (`Ivern`, 427) */ pub const IVERN: Self = Self(427); /// `JHIN` | "Jhin" | "Jhin" | 202
/** Janna (`Janna`, 40) */ pub const JANNA: Self = Self(40); /// `JINX` | "Jinx" | "Jinx" | 222
/** Jarvan IV (`JarvanIV`, 59) */ pub const JARVAN_IV: Self = Self(59); /// `KAI_SA` | "Kai'Sa" | "Kaisa" | 145
/** Jax (`Jax`, 24) */ pub const JAX: Self = Self(24); /// `KALISTA` | "Kalista" | "Kalista" | 429
/** Jayce (`Jayce`, 126) */ pub const JAYCE: Self = Self(126); /// `KARMA` | "Karma" | "Karma" | 43
/** Jhin (`Jhin`, 202) */ pub const JHIN: Self = Self(202); /// `KARTHUS` | "Karthus" | "Karthus" | 30
/** Jinx (`Jinx`, 222) */ pub const JINX: Self = Self(222); /// `KASSADIN` | "Kassadin" | "Kassadin" | 38
/** Kai'Sa (`Kaisa`, 145) */ pub const KAI_SA: Self = Self(145); /// `KATARINA` | "Katarina" | "Katarina" | 55
/** Kalista (`Kalista`, 429) */ pub const KALISTA: Self = Self(429); /// `KAYLE` | "Kayle" | "Kayle" | 10
/** Karma (`Karma`, 43) */ pub const KARMA: Self = Self(43); /// `KAYN` | "Kayn" | "Kayn" | 141
/** Karthus (`Karthus`, 30) */ pub const KARTHUS: Self = Self(30); /// `KENNEN` | "Kennen" | "Kennen" | 85
/** Kassadin (`Kassadin`, 38) */ pub const KASSADIN: Self = Self(38); /// `KHA_ZIX` | "Kha'Zix" | "Khazix" | 121
/** Katarina (`Katarina`, 55) */ pub const KATARINA: Self = Self(55); /// `KINDRED` | "Kindred" | "Kindred" | 203
/** Kayle (`Kayle`, 10) */ pub const KAYLE: Self = Self(10); /// `KLED` | "Kled" | "Kled" | 240
/** Kayn (`Kayn`, 141) */ pub const KAYN: Self = Self(141); /// `KOG_MAW` | "Kog'Maw" | "KogMaw" | 96
/** Kennen (`Kennen`, 85) */ pub const KENNEN: Self = Self(85); /// `LE_BLANC` | "LeBlanc" | "Leblanc" | 7
/** Kha'Zix (`Khazix`, 121) */ pub const KHA_ZIX: Self = Self(121); /// `LEE_SIN` | "Lee Sin" | "LeeSin" | 64
/** Kindred (`Kindred`, 203) */ pub const KINDRED: Self = Self(203); /// `LEONA` | "Leona" | "Leona" | 89
/** Kled (`Kled`, 240) */ pub const KLED: Self = Self(240); /// `LILLIA` | "Lillia" | "Lillia" | 876
/** Kog'Maw (`KogMaw`, 96) */ pub const KOG_MAW: Self = Self(96); /// `LISSANDRA` | "Lissandra" | "Lissandra" | 127
/** LeBlanc (`Leblanc`, 7) */ pub const LE_BLANC: Self = Self(7); /// `LUCIAN` | "Lucian" | "Lucian" | 236
/** Lee Sin (`LeeSin`, 64) */ pub const LEE_SIN: Self = Self(64); /// `LULU` | "Lulu" | "Lulu" | 117
/** Leona (`Leona`, 89) */ pub const LEONA: Self = Self(89); /// `LUX` | "Lux" | "Lux" | 99
/** Lillia (`Lillia`, 876) */ pub const LILLIA: Self = Self(876); /// `MALPHITE` | "Malphite" | "Malphite" | 54
/** Lissandra (`Lissandra`, 127) */ pub const LISSANDRA: Self = Self(127); /// `MALZAHAR` | "Malzahar" | "Malzahar" | 90
/** Lucian (`Lucian`, 236) */ pub const LUCIAN: Self = Self(236); /// `MAOKAI` | "Maokai" | "Maokai" | 57
/** Lulu (`Lulu`, 117) */ pub const LULU: Self = Self(117); /// `MASTER_YI` | "Master Yi" | "MasterYi" | 11
/** Lux (`Lux`, 99) */ pub const LUX: Self = Self(99); /// `MISS_FORTUNE` | "Miss Fortune" | "MissFortune" | 21
/** Malphite (`Malphite`, 54) */ pub const MALPHITE: Self = Self(54); /// `MORDEKAISER` | "Mordekaiser" | "Mordekaiser" | 82
/** Malzahar (`Malzahar`, 90) */ pub const MALZAHAR: Self = Self(90); /// `MORGANA` | "Morgana" | "Morgana" | 25
/** Maokai (`Maokai`, 57) */ pub const MAOKAI: Self = Self(57); /// `NAMI` | "Nami" | "Nami" | 267
/** Master Yi (`MasterYi`, 11) */ pub const MASTER_YI: Self = Self(11); /// `NASUS` | "Nasus" | "Nasus" | 75
/** Miss Fortune (`MissFortune`, 21) */ pub const MISS_FORTUNE: Self = Self(21); /// `NAUTILUS` | "Nautilus" | "Nautilus" | 111
/** Mordekaiser (`Mordekaiser`, 82) */ pub const MORDEKAISER: Self = Self(82); /// `NEEKO` | "Neeko" | "Neeko" | 518
/** Morgana (`Morgana`, 25) */ pub const MORGANA: Self = Self(25); /// `NIDALEE` | "Nidalee" | "Nidalee" | 76
/** Nami (`Nami`, 267) */ pub const NAMI: Self = Self(267); /// `NOCTURNE` | "Nocturne" | "Nocturne" | 56
/** Nasus (`Nasus`, 75) */ pub const NASUS: Self = Self(75); /// `NUNU_WILLUMP` | "Nunu & Willump" | "Nunu" | 20
/** Nautilus (`Nautilus`, 111) */ pub const NAUTILUS: Self = Self(111); /// `OLAF` | "Olaf" | "Olaf" | 2
/** Neeko (`Neeko`, 518) */ pub const NEEKO: Self = Self(518); /// `ORIANNA` | "Orianna" | "Orianna" | 61
/** Nidalee (`Nidalee`, 76) */ pub const NIDALEE: Self = Self(76); /// `ORNN` | "Ornn" | "Ornn" | 516
/** Nocturne (`Nocturne`, 56) */ pub const NOCTURNE: Self = Self(56); /// `PANTHEON` | "Pantheon" | "Pantheon" | 80
/** Nunu & Willump (`Nunu`, 20) */ pub const NUNU_WILLUMP: Self = Self(20); /// `POPPY` | "Poppy" | "Poppy" | 78
/** Olaf (`Olaf`, 2) */ pub const OLAF: Self = Self(2); /// `PYKE` | "Pyke" | "Pyke" | 555
/** Orianna (`Orianna`, 61) */ pub const ORIANNA: Self = Self(61); /// `QIYANA` | "Qiyana" | "Qiyana" | 246
/** Ornn (`Ornn`, 516) */ pub const ORNN: Self = Self(516); /// `QUINN` | "Quinn" | "Quinn" | 133
/** Pantheon (`Pantheon`, 80) */ pub const PANTHEON: Self = Self(80); /// `RAKAN` | "Rakan" | "Rakan" | 497
/** Poppy (`Poppy`, 78) */ pub const POPPY: Self = Self(78); /// `RAMMUS` | "Rammus" | "Rammus" | 33
/** Pyke (`Pyke`, 555) */ pub const PYKE: Self = Self(555); /// `REK_SAI` | "Rek'Sai" | "RekSai" | 421
/** Qiyana (`Qiyana`, 246) */ pub const QIYANA: Self = Self(246); /// `RELL` | "Rell" | "Rell" | 526
/** Quinn (`Quinn`, 133) */ pub const QUINN: Self = Self(133); /// `RENEKTON` | "Renekton" | "Renekton" | 58
/** Rakan (`Rakan`, 497) */ pub const RAKAN: Self = Self(497); /// `RENGAR` | "Rengar" | "Rengar" | 107
/** Rammus (`Rammus`, 33) */ pub const RAMMUS: Self = Self(33); /// `RIVEN` | "Riven" | "Riven" | 92
/** Rek'Sai (`RekSai`, 421) */ pub const REK_SAI: Self = Self(421); /// `RUMBLE` | "Rumble" | "Rumble" | 68
/** Rell (`Rell`, 526) */ pub const RELL: Self = Self(526); /// `RYZE` | "Ryze" | "Ryze" | 13
/** Renekton (`Renekton`, 58) */ pub const RENEKTON: Self = Self(58); /// `SAMIRA` | "Samira" | "Samira" | 360
/** Rengar (`Rengar`, 107) */ pub const RENGAR: Self = Self(107); /// `SEJUANI` | "Sejuani" | "Sejuani" | 113
/** Riven (`Riven`, 92) */ pub const RIVEN: Self = Self(92); /// `SENNA` | "Senna" | "Senna" | 235
/** Rumble (`Rumble`, 68) */ pub const RUMBLE: Self = Self(68); /// `SERAPHINE` | "Seraphine" | "Seraphine" | 147
/** Ryze (`Ryze`, 13) */ pub const RYZE: Self = Self(13); /// `SETT` | "Sett" | "Sett" | 875
/** Samira (`Samira`, 360) */ pub const SAMIRA: Self = Self(360); /// `SHACO` | "Shaco" | "Shaco" | 35
/** Sejuani (`Sejuani`, 113) */ pub const SEJUANI: Self = Self(113); /// `SHEN` | "Shen" | "Shen" | 98
/** Senna (`Senna`, 235) */ pub const SENNA: Self = Self(235); /// `SHYVANA` | "Shyvana" | "Shyvana" | 102
/** Seraphine (`Seraphine`, 147) */ pub const SERAPHINE: Self = Self(147); /// `SINGED` | "Singed" | "Singed" | 27
/** Sett (`Sett`, 875) */ pub const SETT: Self = Self(875); /// `SION` | "Sion" | "Sion" | 14
/** Shaco (`Shaco`, 35) */ pub const SHACO: Self = Self(35); /// `SIVIR` | "Sivir" | "Sivir" | 15
/** Shen (`Shen`, 98) */ pub const SHEN: Self = Self(98); /// `SKARNER` | "Skarner" | "Skarner" | 72
/** Shyvana (`Shyvana`, 102) */ pub const SHYVANA: Self = Self(102); /// `SONA` | "Sona" | "Sona" | 37
/** Singed (`Singed`, 27) */ pub const SINGED: Self = Self(27); /// `SORAKA` | "Soraka" | "Soraka" | 16
/** Sion (`Sion`, 14) */ pub const SION: Self = Self(14); /// `SWAIN` | "Swain" | "Swain" | 50
/** Sivir (`Sivir`, 15) */ pub const SIVIR: Self = Self(15); /// `SYLAS` | "Sylas" | "Sylas" | 517
/** Skarner (`Skarner`, 72) */ pub const SKARNER: Self = Self(72); /// `SYNDRA` | "Syndra" | "Syndra" | 134
/** Sona (`Sona`, 37) */ pub const SONA: Self = Self(37); /// `TAHM_KENCH` | "Tahm Kench" | "TahmKench" | 223
/** Soraka (`Soraka`, 16) */ pub const SORAKA: Self = Self(16); /// `TALIYAH` | "Taliyah" | "Taliyah" | 163
/** Swain (`Swain`, 50) */ pub const SWAIN: Self = Self(50); /// `TALON` | "Talon" | "Talon" | 91
/** Sylas (`Sylas`, 517) */ pub const SYLAS: Self = Self(517); /// `TARIC` | "Taric" | "Taric" | 44
/** Syndra (`Syndra`, 134) */ pub const SYNDRA: Self = Self(134); /// `TEEMO` | "Teemo" | "Teemo" | 17
/** Tahm Kench (`TahmKench`, 223) */ pub const TAHM_KENCH: Self = Self(223); /// `THRESH` | "Thresh" | "Thresh" | 412
/** Taliyah (`Taliyah`, 163) */ pub const TALIYAH: Self = Self(163); /// `TRISTANA` | "Tristana" | "Tristana" | 18
/** Talon (`Talon`, 91) */ pub const TALON: Self = Self(91); /// `TRUNDLE` | "Trundle" | "Trundle" | 48
/** Taric (`Taric`, 44) */ pub const TARIC: Self = Self(44); /// `TRYNDAMERE` | "Tryndamere" | "Tryndamere" | 23
/** Teemo (`Teemo`, 17) */ pub const TEEMO: Self = Self(17); /// `TWISTED_FATE` | "Twisted Fate" | "TwistedFate" | 4
/** Thresh (`Thresh`, 412) */ pub const THRESH: Self = Self(412); /// `TWITCH` | "Twitch" | "Twitch" | 29
/** Tristana (`Tristana`, 18) */ pub const TRISTANA: Self = Self(18); /// `UDYR` | "Udyr" | "Udyr" | 77
/** Trundle (`Trundle`, 48) */ pub const TRUNDLE: Self = Self(48); /// `URGOT` | "Urgot" | "Urgot" | 6
/** Tryndamere (`Tryndamere`, 23) */ pub const TRYNDAMERE: Self = Self(23); /// `VARUS` | "Varus" | "Varus" | 110
/** Twisted Fate (`TwistedFate`, 4) */ pub const TWISTED_FATE: Self = Self(4); /// `VAYNE` | "Vayne" | "Vayne" | 67
/** Twitch (`Twitch`, 29) */ pub const TWITCH: Self = Self(29); /// `VEIGAR` | "Veigar" | "Veigar" | 45
/** Udyr (`Udyr`, 77) */ pub const UDYR: Self = Self(77); /// `VEL_KOZ` | "Vel'Koz" | "Velkoz" | 161
/** Urgot (`Urgot`, 6) */ pub const URGOT: Self = Self(6); /// `VI` | "Vi" | "Vi" | 254
/** Varus (`Varus`, 110) */ pub const VARUS: Self = Self(110); /// `VIEGO` | "Viego" | "Viego" | 234
/** Vayne (`Vayne`, 67) */ pub const VAYNE: Self = Self(67); /// `VIKTOR` | "Viktor" | "Viktor" | 112
/** Veigar (`Veigar`, 45) */ pub const VEIGAR: Self = Self(45); /// `VLADIMIR` | "Vladimir" | "Vladimir" | 8
/** Vel'Koz (`Velkoz`, 161) */ pub const VEL_KOZ: Self = Self(161); /// `VOLIBEAR` | "Volibear" | "Volibear" | 106
/** Vi (`Vi`, 254) */ pub const VI: Self = Self(254); /// `WARWICK` | "Warwick" | "Warwick" | 19
/** Viego (`Viego`, 234) */ pub const VIEGO: Self = Self(234); /// `WUKONG` | "Wukong" | "MonkeyKing" | 62
/** Viktor (`Viktor`, 112) */ pub const VIKTOR: Self = Self(112); /// `XAYAH` | "Xayah" | "Xayah" | 498
/** Vladimir (`Vladimir`, 8) */ pub const VLADIMIR: Self = Self(8); /// `XERATH` | "Xerath" | "Xerath" | 101
/** Volibear (`Volibear`, 106) */ pub const VOLIBEAR: Self = Self(106); /// `XIN_ZHAO` | "Xin Zhao" | "XinZhao" | 5
/** Warwick (`Warwick`, 19) */ pub const WARWICK: Self = Self(19); /// `YASUO` | "Yasuo" | "Yasuo" | 157
/** Wukong (`MonkeyKing`, 62) */ pub const WUKONG: Self = Self(62); /// `YONE` | "Yone" | "Yone" | 777
/** Xayah (`Xayah`, 498) */ pub const XAYAH: Self = Self(498); /// `YORICK` | "Yorick" | "Yorick" | 83
/** Xerath (`Xerath`, 101) */ pub const XERATH: Self = Self(101); /// `YUUMI` | "Yuumi" | "Yuumi" | 350
/** Xin Zhao (`XinZhao`, 5) */ pub const XIN_ZHAO: Self = Self(5); /// `ZAC` | "Zac" | "Zac" | 154
/** Yasuo (`Yasuo`, 157) */ pub const YASUO: Self = Self(157); /// `ZED` | "Zed" | "Zed" | 238
/** Yone (`Yone`, 777) */ pub const YONE: Self = Self(777); /// `ZIGGS` | "Ziggs" | "Ziggs" | 115
/** Yorick (`Yorick`, 83) */ pub const YORICK: Self = Self(83); /// `ZILEAN` | "Zilean" | "Zilean" | 26
/** Yuumi (`Yuumi`, 350) */ pub const YUUMI: Self = Self(350); /// `ZOE` | "Zoe" | "Zoe" | 142
/** Zac (`Zac`, 154) */ pub const ZAC: Self = Self(154); /// `ZYRA` | "Zyra" | "Zyra" | 143
/** Zed (`Zed`, 238) */ pub const ZED: Self = Self(238); #[derive(Serialize, Deserialize)]
/** Ziggs (`Ziggs`, 115) */ pub const ZIGGS: Self = Self(115); #[serde(transparent)]
/** Zilean (`Zilean`, 26) */ pub const ZILEAN: Self = Self(26); pub newtype_enum Champion(i16) {
/** Zoe (`Zoe`, 142) */ pub const ZOE: Self = Self(142); AATROX = 266,
/** Zyra (`Zyra`, 143) */ pub const ZYRA: Self = Self(143); AHRI = 103,
AKALI = 84,
ALISTAR = 12,
AMUMU = 32,
ANIVIA = 34,
ANNIE = 1,
APHELIOS = 523,
ASHE = 22,
AURELION_SOL = 136,
AZIR = 268,
BARD = 432,
BLITZCRANK = 53,
BRAND = 63,
BRAUM = 201,
CAITLYN = 51,
CAMILLE = 164,
CASSIOPEIA = 69,
CHO_GATH = 31,
CORKI = 42,
DARIUS = 122,
DIANA = 131,
DR_MUNDO = 36,
DRAVEN = 119,
EKKO = 245,
ELISE = 60,
EVELYNN = 28,
EZREAL = 81,
FIDDLESTICKS = 9,
FIORA = 114,
FIZZ = 105,
GALIO = 3,
GANGPLANK = 41,
GAREN = 86,
GNAR = 150,
GRAGAS = 79,
GRAVES = 104,
GWEN = 887,
HECARIM = 120,
HEIMERDINGER = 74,
ILLAOI = 420,
IRELIA = 39,
IVERN = 427,
JANNA = 40,
JARVAN_IV = 59,
JAX = 24,
JAYCE = 126,
JHIN = 202,
JINX = 222,
KAI_SA = 145,
KALISTA = 429,
KARMA = 43,
KARTHUS = 30,
KASSADIN = 38,
KATARINA = 55,
KAYLE = 10,
KAYN = 141,
KENNEN = 85,
KHA_ZIX = 121,
KINDRED = 203,
KLED = 240,
KOG_MAW = 96,
LE_BLANC = 7,
LEE_SIN = 64,
LEONA = 89,
LILLIA = 876,
LISSANDRA = 127,
LUCIAN = 236,
LULU = 117,
LUX = 99,
MALPHITE = 54,
MALZAHAR = 90,
MAOKAI = 57,
MASTER_YI = 11,
MISS_FORTUNE = 21,
MORDEKAISER = 82,
MORGANA = 25,
NAMI = 267,
NASUS = 75,
NAUTILUS = 111,
NEEKO = 518,
NIDALEE = 76,
NOCTURNE = 56,
NUNU_WILLUMP = 20,
OLAF = 2,
ORIANNA = 61,
ORNN = 516,
PANTHEON = 80,
POPPY = 78,
PYKE = 555,
QIYANA = 246,
QUINN = 133,
RAKAN = 497,
RAMMUS = 33,
REK_SAI = 421,
RELL = 526,
RENEKTON = 58,
RENGAR = 107,
RIVEN = 92,
RUMBLE = 68,
RYZE = 13,
SAMIRA = 360,
SEJUANI = 113,
SENNA = 235,
SERAPHINE = 147,
SETT = 875,
SHACO = 35,
SHEN = 98,
SHYVANA = 102,
SINGED = 27,
SION = 14,
SIVIR = 15,
SKARNER = 72,
SONA = 37,
SORAKA = 16,
SWAIN = 50,
SYLAS = 517,
SYNDRA = 134,
TAHM_KENCH = 223,
TALIYAH = 163,
TALON = 91,
TARIC = 44,
TEEMO = 17,
THRESH = 412,
TRISTANA = 18,
TRUNDLE = 48,
TRYNDAMERE = 23,
TWISTED_FATE = 4,
TWITCH = 29,
UDYR = 77,
URGOT = 6,
VARUS = 110,
VAYNE = 67,
VEIGAR = 45,
VEL_KOZ = 161,
VI = 254,
VIEGO = 234,
VIKTOR = 112,
VLADIMIR = 8,
VOLIBEAR = 106,
WARWICK = 19,
WUKONG = 62,
XAYAH = 498,
XERATH = 101,
XIN_ZHAO = 5,
YASUO = 157,
YONE = 777,
YORICK = 83,
YUUMI = 350,
ZAC = 154,
ZED = 238,
ZIGGS = 115,
ZILEAN = 26,
ZOE = 142,
ZYRA = 143,
}
} }
impl Champion { impl Champion {
/// Array containing all Champion variants, ordered by their id value.
pub const ALL: [Self; 155] = [
Self::ANNIE, Self::OLAF, Self::GALIO, Self::TWISTED_FATE, Self::XIN_ZHAO, Self::URGOT, Self::LE_BLANC, Self::VLADIMIR,
Self::FIDDLESTICKS, Self::KAYLE, Self::MASTER_YI, Self::ALISTAR, Self::RYZE, Self::SION, Self::SIVIR, Self::SORAKA,
Self::TEEMO, Self::TRISTANA, Self::WARWICK, Self::NUNU_WILLUMP, Self::MISS_FORTUNE, Self::ASHE, Self::TRYNDAMERE, Self::JAX,
Self::MORGANA, Self::ZILEAN, Self::SINGED, Self::EVELYNN, Self::TWITCH, Self::KARTHUS, Self::CHO_GATH, Self::AMUMU,
Self::RAMMUS, Self::ANIVIA, Self::SHACO, Self::DR_MUNDO, Self::SONA, Self::KASSADIN, Self::IRELIA, Self::JANNA,
Self::GANGPLANK, Self::CORKI, Self::KARMA, Self::TARIC, Self::VEIGAR, Self::TRUNDLE, Self::SWAIN, Self::CAITLYN,
Self::BLITZCRANK, Self::MALPHITE, Self::KATARINA, Self::NOCTURNE, Self::MAOKAI, Self::RENEKTON, Self::JARVAN_IV, Self::ELISE,
Self::ORIANNA, Self::WUKONG, Self::BRAND, Self::LEE_SIN, Self::VAYNE, Self::RUMBLE, Self::CASSIOPEIA, Self::SKARNER,
Self::HEIMERDINGER, Self::NASUS, Self::NIDALEE, Self::UDYR, Self::POPPY, Self::GRAGAS, Self::PANTHEON, Self::EZREAL,
Self::MORDEKAISER, Self::YORICK, Self::AKALI, Self::KENNEN, Self::GAREN, Self::LEONA, Self::MALZAHAR, Self::TALON,
Self::RIVEN, Self::KOG_MAW, Self::SHEN, Self::LUX, Self::XERATH, Self::SHYVANA, Self::AHRI, Self::GRAVES,
Self::FIZZ, Self::VOLIBEAR, Self::RENGAR, Self::VARUS, Self::NAUTILUS, Self::VIKTOR, Self::SEJUANI, Self::FIORA,
Self::ZIGGS, Self::LULU, Self::DRAVEN, Self::HECARIM, Self::KHA_ZIX, Self::DARIUS, Self::JAYCE, Self::LISSANDRA,
Self::DIANA, Self::QUINN, Self::SYNDRA, Self::AURELION_SOL, Self::KAYN, Self::ZOE, Self::ZYRA, Self::KAI_SA,
Self::SERAPHINE, Self::GNAR, Self::ZAC, Self::YASUO, Self::VEL_KOZ, Self::TALIYAH, Self::CAMILLE, Self::BRAUM,
Self::JHIN, Self::KINDRED, Self::JINX, Self::TAHM_KENCH, Self::VIEGO, Self::SENNA, Self::LUCIAN, Self::ZED,
Self::KLED, Self::EKKO, Self::QIYANA, Self::VI, Self::AATROX, Self::NAMI, Self::AZIR, Self::YUUMI,
Self::SAMIRA, Self::THRESH, Self::ILLAOI, Self::REK_SAI, Self::IVERN, Self::KALISTA, Self::BARD, Self::RAKAN,
Self::XAYAH, Self::ORNN, Self::SYLAS, Self::NEEKO, Self::APHELIOS, Self::RELL, Self::PYKE, Self::YONE,
Self::SETT, Self::LILLIA, Self::GWEN,
];
pub const fn is_known(self) -> bool {
match self {
Self::AATROX => true,
Self::AHRI => true,
Self::AKALI => true,
Self::ALISTAR => true,
Self::AMUMU => true,
Self::ANIVIA => true,
Self::ANNIE => true,
Self::APHELIOS => true,
Self::ASHE => true,
Self::AURELION_SOL => true,
Self::AZIR => true,
Self::BARD => true,
Self::BLITZCRANK => true,
Self::BRAND => true,
Self::BRAUM => true,
Self::CAITLYN => true,
Self::CAMILLE => true,
Self::CASSIOPEIA => true,
Self::CHO_GATH => true,
Self::CORKI => true,
Self::DARIUS => true,
Self::DIANA => true,
Self::DR_MUNDO => true,
Self::DRAVEN => true,
Self::EKKO => true,
Self::ELISE => true,
Self::EVELYNN => true,
Self::EZREAL => true,
Self::FIDDLESTICKS => true,
Self::FIORA => true,
Self::FIZZ => true,
Self::GALIO => true,
Self::GANGPLANK => true,
Self::GAREN => true,
Self::GNAR => true,
Self::GRAGAS => true,
Self::GRAVES => true,
Self::GWEN => true,
Self::HECARIM => true,
Self::HEIMERDINGER => true,
Self::ILLAOI => true,
Self::IRELIA => true,
Self::IVERN => true,
Self::JANNA => true,
Self::JARVAN_IV => true,
Self::JAX => true,
Self::JAYCE => true,
Self::JHIN => true,
Self::JINX => true,
Self::KAI_SA => true,
Self::KALISTA => true,
Self::KARMA => true,
Self::KARTHUS => true,
Self::KASSADIN => true,
Self::KATARINA => true,
Self::KAYLE => true,
Self::KAYN => true,
Self::KENNEN => true,
Self::KHA_ZIX => true,
Self::KINDRED => true,
Self::KLED => true,
Self::KOG_MAW => true,
Self::LE_BLANC => true,
Self::LEE_SIN => true,
Self::LEONA => true,
Self::LILLIA => true,
Self::LISSANDRA => true,
Self::LUCIAN => true,
Self::LULU => true,
Self::LUX => true,
Self::MALPHITE => true,
Self::MALZAHAR => true,
Self::MAOKAI => true,
Self::MASTER_YI => true,
Self::MISS_FORTUNE => true,
Self::MORDEKAISER => true,
Self::MORGANA => true,
Self::NAMI => true,
Self::NASUS => true,
Self::NAUTILUS => true,
Self::NEEKO => true,
Self::NIDALEE => true,
Self::NOCTURNE => true,
Self::NUNU_WILLUMP => true,
Self::OLAF => true,
Self::ORIANNA => true,
Self::ORNN => true,
Self::PANTHEON => true,
Self::POPPY => true,
Self::PYKE => true,
Self::QIYANA => true,
Self::QUINN => true,
Self::RAKAN => true,
Self::RAMMUS => true,
Self::REK_SAI => true,
Self::RELL => true,
Self::RENEKTON => true,
Self::RENGAR => true,
Self::RIVEN => true,
Self::RUMBLE => true,
Self::RYZE => true,
Self::SAMIRA => true,
Self::SEJUANI => true,
Self::SENNA => true,
Self::SERAPHINE => true,
Self::SETT => true,
Self::SHACO => true,
Self::SHEN => true,
Self::SHYVANA => true,
Self::SINGED => true,
Self::SION => true,
Self::SIVIR => true,
Self::SKARNER => true,
Self::SONA => true,
Self::SORAKA => true,
Self::SWAIN => true,
Self::SYLAS => true,
Self::SYNDRA => true,
Self::TAHM_KENCH => true,
Self::TALIYAH => true,
Self::TALON => true,
Self::TARIC => true,
Self::TEEMO => true,
Self::THRESH => true,
Self::TRISTANA => true,
Self::TRUNDLE => true,
Self::TRYNDAMERE => true,
Self::TWISTED_FATE => true,
Self::TWITCH => true,
Self::UDYR => true,
Self::URGOT => true,
Self::VARUS => true,
Self::VAYNE => true,
Self::VEIGAR => true,
Self::VEL_KOZ => true,
Self::VI => true,
Self::VIEGO => true,
Self::VIKTOR => true,
Self::VLADIMIR => true,
Self::VOLIBEAR => true,
Self::WARWICK => true,
Self::WUKONG => true,
Self::XAYAH => true,
Self::XERATH => true,
Self::XIN_ZHAO => true,
Self::YASUO => true,
Self::YONE => true,
Self::YORICK => true,
Self::YUUMI => true,
Self::ZAC => true,
Self::ZED => true,
Self::ZIGGS => true,
Self::ZILEAN => true,
Self::ZOE => true,
Self::ZYRA => true,
_ => false,
}
}
/// The champion's name (`en_US` localization). /// The champion's name (`en_US` localization).
pub const fn name(self) -> Option<&'static str> { pub const fn name(self) -> Option<&'static str> {
match self { match self {
@ -534,16 +502,16 @@ impl Champion {
/// This is generally the `en_US` name with spaces and punctuation removed, /// This is generally the `en_US` name with spaces and punctuation removed,
/// capitalization preserved, however the follow are exceptions: /// capitalization preserved, however the follow are exceptions:
/// ///
/// Field | Name | Identifier /// Field | Name | Identifier | Id
/// --------|------|----------- /// ---|---|---|---
/// `CHO_GATH` | "Cho'Gath" | "Chogath" /// `CHO_GATH` | "Cho'Gath" | "Chogath" | 31
/// `FIDDLESTICKS` | "Fiddlesticks" | "FiddleSticks" /// `FIDDLESTICKS` | "Fiddlesticks" | "FiddleSticks" | 9
/// `KAI_SA` | "Kai'Sa" | "Kaisa" /// `KAI_SA` | "Kai'Sa" | "Kaisa" | 145
/// `KHA_ZIX` | "Kha'Zix" | "Khazix" /// `KHA_ZIX` | "Kha'Zix" | "Khazix" | 121
/// `LE_BLANC` | "LeBlanc" | "Leblanc" /// `LE_BLANC` | "LeBlanc" | "Leblanc" | 7
/// `NUNU_WILLUMP` | "Nunu & Willump" | "Nunu" /// `NUNU_WILLUMP` | "Nunu & Willump" | "Nunu" | 20
/// `VEL_KOZ` | "Vel'Koz" | "Velkoz" /// `VEL_KOZ` | "Vel'Koz" | "Velkoz" | 161
/// `WUKONG` | "Wukong" | "MonkeyKing" /// `WUKONG` | "Wukong" | "MonkeyKing" | 62
pub const fn identifier(self) -> Option<&'static str> { pub const fn identifier(self) -> Option<&'static str> {
match self { match self {
Self::AATROX => Some("Aatrox"), Self::AATROX => Some("Aatrox"),
@ -890,27 +858,3 @@ impl std::convert::TryFrom<&str> for Champion {
<Self as std::str::FromStr>::from_str(value) <Self as std::str::FromStr>::from_str(value)
} }
} }
impl std::convert::From<i16> for Champion {
fn from(value: i16) -> Self {
Self(value)
}
}
impl std::convert::From<Champion> for i16 {
fn from(value: Champion) -> Self {
value.0
}
}
impl std::fmt::Display for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::fmt::Debug for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Champion({} {})", self.0, self.identifier().unwrap_or("UNKNOWN"))
}
}

View file

@ -1,23 +0,0 @@
#![macro_use]
macro_rules! serde_string {
( $x:ty ) => {
impl<'de> serde::de::Deserialize<'de> for $x
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>
{
let s = String::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}
impl serde::ser::Serialize for $x {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(self.as_ref())
}
}
};
}

100
src/consts/macros.rs Normal file
View file

@ -0,0 +1,100 @@
#![macro_use]
macro_rules! serde_string {
( $name:ident ) => {
impl<'de> serde::de::Deserialize<'de> for $name {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>
{
let s = String::deserialize(deserializer)?;
s.parse().map_err(serde::de::Error::custom)
}
}
impl serde::ser::Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::ser::Serializer,
{
serializer.serialize_str(self.as_ref())
}
}
};
}
macro_rules! arr {
(
$( #[$attr:meta] )*
$v:vis $id:ident $name:ident: [$ty:ty; _] = $value:expr
) => {
$( #[$attr] )*
$v $id $name: [$ty; $value.len()] = $value;
}
}
macro_rules! newtype_enum {
{
$( #[$attr:meta] )*
$v:vis newtype_enum $name:ident($repr:ident) {
$(
$( #[$var_attr:meta] )*
$var_name:ident = $var_val:expr,
)*
}
} => {
$( #[$attr] )*
#[derive(Copy, Clone)]
#[derive(PartialEq, Eq, PartialOrd, Ord)]
#[repr(transparent)]
$v struct $name($v $repr);
impl $name {
$(
$( #[$var_attr] )*
$v const $var_name: Self = Self( $var_val );
)*
}
impl $name {
arr!{
#[doc = "Array containing all variants, ordered by their id value."]
pub const ALL_KNOWN: [Self; _] = [
$( Self::$var_name, )*
]
}
#[doc = "If this is one of the known variants."]
$v fn is_known(self) -> bool {
match self {
$(
Self::$var_name => true,
)*
_ => false,
}
}
}
impl std::convert::From<$repr> for $name {
fn from(value: $repr ) -> Self {
Self(value)
}
}
impl std::convert::From<$name> for $repr {
fn from(value: $name ) -> Self {
value.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}({}{})", stringify!($name), self.0, if self.is_known() { "" } else { "?" })
}
}
}
}

View file

@ -6,7 +6,7 @@
#![allow(deprecated)] #![allow(deprecated)]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
mod macro_serde_string; mod macros;
mod champion; mod champion;
pub use champion::*; pub use champion::*;

View file

@ -18,59 +18,36 @@
use serde::{ Serialize, Deserialize }; use serde::{ Serialize, Deserialize };
/// League of Legends champions. newtype_enum! {
/// /// A League of Legends champion.
/// The documentation of each const field specifies:<br> ///
/// NAME (`IDENTIFIER`, ID). /// This newtype acts as a C-like enum; each variant corresponds to an
/// /// integer value. Using a newtype allows _unknown_ variants to be
/// Implements [IntoEnumIterator](super::IntoEnumIterator). /// represented. This is important when Riot adds new champions.
#[derive(Serialize, Deserialize)] ///
#[derive(Copy, Clone)] /// Field | Name | Identifier | Id
#[derive(PartialEq, Eq, PartialOrd, Ord)] /// ---|---|---|---
#[serde(transparent)]
#[repr(transparent)]
pub struct Champion(pub i16);
impl Champion {
{{ {{
for (const { id, alias, name } of champions) { for (const { id, alias, name } of champions) {
}} }}
/** {{= `${name} (\`${alias}\`, ${id})`.padEnd(33) }} */ pub const {{= `${constName(name)}:`.padEnd(1 + constNamePad) }} Self = Self({{= id }}); /// `{{= constName(name) }}` | "{{= name }}" | "{{= alias }}" | {{= id }}
{{ {{
} }
}} }}
#[derive(Serialize, Deserialize)]
#[serde(transparent)]
pub newtype_enum Champion(i16) {
{{
for (const { id, alias, name } of champions) {
}}
{{= constName(name) }} = {{= id }},
{{
}
}}
}
} }
impl Champion { impl Champion {
/// Array containing all Champion variants, ordered by their id value.
pub const ALL: [Self; {{= champions.length }}] = [
{{
{
const champNames = require('./.champion.json').slice(1).map(({ name }) => `Self::${constName(name)},`.padEnd(8 + constNamePad));
const step = 8;
for (let i = 0; i < champNames.length; i += step) {
}}
{{= champNames.slice(i, i + step).join('').trim() }}
{{
}
}
}}
];
pub const fn is_known(self) -> bool {
match self {
{{
for (const { name, alias } of champions) {
}}
Self::{{= constName(name).padEnd(constNamePad) }} => true,
{{
}
}}
_ => false,
}
}
/// The champion's name (`en_US` localization). /// The champion's name (`en_US` localization).
pub const fn name(self) -> Option<&'static str> { pub const fn name(self) -> Option<&'static str> {
match self { match self {
@ -91,13 +68,13 @@ impl Champion {
/// This is generally the `en_US` name with spaces and punctuation removed, /// This is generally the `en_US` name with spaces and punctuation removed,
/// capitalization preserved, however the follow are exceptions: /// capitalization preserved, however the follow are exceptions:
/// ///
/// Field | Name | Identifier /// Field | Name | Identifier | Id
/// --------|------|----------- /// ---|---|---|---
{{ {{
for (const { name, alias } of champions) { for (const { id, alias, name } of champions) {
if (name.replace(/[^a-zA-Z0-9]+/, '') !== alias) { if (name.replace(/[^a-zA-Z0-9]+/, '') !== alias) {
}} }}
/// `{{= constName(name) }}` | "{{= name }}" | "{{= alias }}" /// `{{= constName(name) }}` | "{{= name }}" | "{{= alias }}" | {{= id }}
{{ {{
} }
} }
@ -150,27 +127,3 @@ impl std::convert::TryFrom<&str> for Champion {
<Self as std::str::FromStr>::from_str(value) <Self as std::str::FromStr>::from_str(value)
} }
} }
impl std::convert::From<i16> for Champion {
fn from(value: i16) -> Self {
Self(value)
}
}
impl std::convert::From<Champion> for i16 {
fn from(value: Champion) -> Self {
value.0
}
}
impl std::fmt::Display for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
}
}
impl std::fmt::Debug for Champion {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Champion({} {})", self.0, self.identifier().unwrap_or("UNKNOWN"))
}
}