forked from mirror/Riven
Remove serde_string! macro in favor of #[derive(Serialize, Deserialize)]
As pointed out in #33
This commit is contained in:
parent
ede1247bf8
commit
038e5eb493
8 changed files with 15 additions and 36 deletions
|
@ -1,6 +1,7 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use num_enum::{ IntoPrimitive, TryFromPrimitive };
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
||||
|
||||
|
@ -15,6 +16,7 @@ use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
|||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
||||
#[derive(IntoPrimitive, TryFromPrimitive)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum Division {
|
||||
/// Division 1, the best/highest division in a [`Tier`](crate::consts::Tier), or the only division in
|
||||
|
@ -31,8 +33,6 @@ pub enum Division {
|
|||
V = 5,
|
||||
}
|
||||
|
||||
serde_string!(Division);
|
||||
|
||||
/// Returns a DoubleEndedIterator of I, II, III, IV.
|
||||
/// Ordered from high rank (I) to low (IV).
|
||||
/// Excludes V, which is deprecated.
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
// //
|
||||
///////////////////////////////////////////////
|
||||
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum_macros::{ EnumString, IntoStaticStr };
|
||||
|
||||
/// League of Legends game mode, such as Classic,
|
||||
|
@ -14,6 +15,7 @@ use strum_macros::{ EnumString, IntoStaticStr };
|
|||
#[derive(Debug, Clone)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum GameMode {
|
||||
/// Catch-all variant for new, unknown game modes.
|
||||
|
@ -69,4 +71,3 @@ pub enum GameMode {
|
|||
}
|
||||
|
||||
string_enum_str!(GameMode);
|
||||
serde_string!(GameMode);
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
// //
|
||||
///////////////////////////////////////////////
|
||||
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
||||
|
||||
/// League of Legends game type: matched game, custom game, or tutorial game.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum GameType {
|
||||
/// Custom games
|
||||
|
@ -21,5 +23,3 @@ pub enum GameType {
|
|||
/// Tutorial games
|
||||
TUTORIAL_GAME,
|
||||
}
|
||||
|
||||
serde_string!(GameType);
|
||||
|
|
|
@ -1,28 +1,5 @@
|
|||
#![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! string_enum_str {
|
||||
( $name:ident ) => {
|
||||
impl AsRef<str> for $name {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
use serde::{ Serialize, Deserialize };
|
||||
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
||||
|
||||
/// LoL or TFT ranked queue types.
|
||||
|
@ -5,6 +6,7 @@ use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
|||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub enum QueueType {
|
||||
/// League of Legends, Summoner's Rift (5v5), Ranked Solo Queue.
|
||||
RANKED_SOLO_5x5,
|
||||
|
@ -20,8 +22,6 @@ pub enum QueueType {
|
|||
RANKED_TFT_PAIRS
|
||||
}
|
||||
|
||||
serde_string!(QueueType);
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
use strum::IntoEnumIterator;
|
||||
use num_enum::{ IntoPrimitive, TryFromPrimitive };
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
||||
|
||||
/// LoL and TFT ranked tiers, such as gold, diamond, challenger, etc.
|
||||
|
@ -13,6 +14,7 @@ use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
|||
#[derive(Eq, PartialEq, Hash, PartialOrd, Ord)]
|
||||
#[derive(IntoPrimitive, TryFromPrimitive)]
|
||||
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum Tier {
|
||||
/// Challenger, the highest tier, an apex tier. Repr: `220_u8`.
|
||||
|
@ -38,8 +40,6 @@ pub enum Tier {
|
|||
UNRANKED = 0,
|
||||
}
|
||||
|
||||
serde_string!(Tier);
|
||||
|
||||
impl Tier {
|
||||
/// If this tier is an apex tier: [`Self::MASTER`], [`Self::GRANDMASTER`],
|
||||
/// or [`Self::CHALLENGER`]. Returns false for [`Self::UNRANKED`].
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
const gameModes = require('./.gameModes.json');
|
||||
}}{{= dotUtils.preamble() }}
|
||||
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum_macros::{ EnumString, IntoStaticStr };
|
||||
|
||||
/// League of Legends game mode, such as Classic,
|
||||
|
@ -11,6 +12,7 @@ use strum_macros::{ EnumString, IntoStaticStr };
|
|||
#[derive(Debug, Clone)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum GameMode {
|
||||
/// Catch-all variant for new, unknown game modes.
|
||||
|
@ -31,4 +33,3 @@ pub enum GameMode {
|
|||
}
|
||||
|
||||
string_enum_str!(GameMode);
|
||||
serde_string!(GameMode);
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
const gameTypes = require('./.gameTypes.json');
|
||||
}}{{= dotUtils.preamble() }}
|
||||
|
||||
use serde::{ Serialize, Deserialize };
|
||||
use strum_macros::{ EnumString, Display, AsRefStr, IntoStaticStr };
|
||||
|
||||
/// League of Legends game type: matched game, custom game, or tutorial game.
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
#[derive(Eq, PartialEq, Hash)]
|
||||
#[derive(EnumString, Display, AsRefStr, IntoStaticStr)]
|
||||
#[derive(Serialize, Deserialize)]
|
||||
#[repr(u8)]
|
||||
pub enum GameType {
|
||||
{{
|
||||
|
@ -23,5 +25,3 @@ pub enum GameType {
|
|||
}
|
||||
}}
|
||||
}
|
||||
|
||||
serde_string!(GameType);
|
||||
|
|
Loading…
Reference in a new issue