mirror of
https://github.com/MingweiSamuel/Riven.git
synced 2024-12-27 03:16:33 +00:00
fix: cleanup loose GameType
serde code
This commit is contained in:
parent
95c3ccbe0b
commit
c5810076fc
3 changed files with 1 additions and 67 deletions
|
@ -31,38 +31,5 @@ pub enum GameType {
|
||||||
TUTORIAL_GAME,
|
TUTORIAL_GAME,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameType {
|
|
||||||
/// https://github.com/RiotGames/developer-relations/issues/898
|
|
||||||
pub(crate) fn serialize_empty<S>(
|
|
||||||
val: &Option<Self>,
|
|
||||||
serializer: S,
|
|
||||||
) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: serde::ser::Serializer,
|
|
||||||
{
|
|
||||||
use serde::ser::Serialize;
|
|
||||||
if let Some(val) = val {
|
|
||||||
val.serialize(serializer)
|
|
||||||
} else {
|
|
||||||
"".serialize(serializer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://github.com/RiotGames/developer-relations/issues/898
|
|
||||||
pub(crate) fn deserialize_empty<'de, D>(
|
|
||||||
deserializer: D,
|
|
||||||
) -> Result<Option<Self>, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::de::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use serde::de::IntoDeserializer;
|
|
||||||
let opt = Option::<String>::deserialize(deserializer)?;
|
|
||||||
match opt.as_deref() {
|
|
||||||
None | Some("") => Ok(None),
|
|
||||||
Some(s) => Self::deserialize(s.into_deserializer()).map(Some)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
|
@ -29,38 +29,5 @@ pub enum GameType {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GameType {
|
|
||||||
/// https://github.com/RiotGames/developer-relations/issues/898
|
|
||||||
pub(crate) fn serialize_empty<S>(
|
|
||||||
val: &Option<Self>,
|
|
||||||
serializer: S,
|
|
||||||
) -> Result<S::Ok, S::Error>
|
|
||||||
where
|
|
||||||
S: serde::ser::Serializer,
|
|
||||||
{
|
|
||||||
use serde::ser::Serialize;
|
|
||||||
if let Some(val) = val {
|
|
||||||
val.serialize(serializer)
|
|
||||||
} else {
|
|
||||||
"".serialize(serializer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// https://github.com/RiotGames/developer-relations/issues/898
|
|
||||||
pub(crate) fn deserialize_empty<'de, D>(
|
|
||||||
deserializer: D,
|
|
||||||
) -> Result<Option<Self>, D::Error>
|
|
||||||
where
|
|
||||||
D: serde::de::Deserializer<'de>,
|
|
||||||
{
|
|
||||||
use serde::de::IntoDeserializer;
|
|
||||||
let opt = Option::<String>::deserialize(deserializer)?;
|
|
||||||
match opt.as_deref() {
|
|
||||||
None | Some("") => Ok(None),
|
|
||||||
Some(s) => Self::deserialize(s.into_deserializer()).map(Some)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test;
|
mod test;
|
||||||
|
|
|
@ -73,7 +73,7 @@ pub mod {{= dotUtils.changeCase.snakeCase(endpoint) }} {
|
||||||
/// Will be `None` if empty string is returned: https://github.com/RiotGames/developer-relations/issues/898
|
/// Will be `None` if empty string is returned: https://github.com/RiotGames/developer-relations/issues/898
|
||||||
#[serde(serialize_with = "crate::consts::serialize_empty_string_none")]
|
#[serde(serialize_with = "crate::consts::serialize_empty_string_none")]
|
||||||
#[serde(deserialize_with = "crate::consts::deserialize_empty_string_none")]
|
#[serde(deserialize_with = "crate::consts::deserialize_empty_string_none")]
|
||||||
pub {{= name }}: Option<{{= dotUtils.stringifyType(prop, {}) }}>,
|
pub {{= name }}: Option<crate::consts::GameType>,
|
||||||
{{??}}
|
{{??}}
|
||||||
pub {{= name }}: {{= dotUtils.stringifyType(prop, { optional }) }},
|
pub {{= name }}: {{= dotUtils.stringifyType(prop, { optional }) }},
|
||||||
{{?}}
|
{{?}}
|
||||||
|
|
Loading…
Reference in a new issue