fix: cleanup loose GameType serde code

This commit is contained in:
Mingwei Samuel 2024-03-05 11:54:53 -08:00
parent 95c3ccbe0b
commit c5810076fc
3 changed files with 1 additions and 67 deletions

View file

@ -31,38 +31,5 @@ pub enum GameType {
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)]
mod test;

View file

@ -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)]
mod test;

View file

@ -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
#[serde(serialize_with = "crate::consts::serialize_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 }) }},
{{?}}