From abbc79fb1ba9a31cc040045a96680b09cc59a88e Mon Sep 17 00:00:00 2001 From: Cedric Kienzler Date: Fri, 29 Nov 2024 12:50:38 +0100 Subject: [PATCH] fix(GitHubKind): do no reimplement (de)serialization, relying on serde instead --- src/helpers/github.rs | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/src/helpers/github.rs b/src/helpers/github.rs index 842a26b..b504735 100644 --- a/src/helpers/github.rs +++ b/src/helpers/github.rs @@ -569,10 +569,13 @@ impl MetadataSource for GitHubReleaseAsset { } #[allow(dead_code)] -#[derive(PartialEq, Debug, Clone)] +#[derive(PartialEq, Debug, Clone, serde::Serialize, serde::Deserialize)] pub enum GitHubKind { + #[serde(rename="github/repo")] Repo, + #[serde(rename="github/star")] Star, + #[serde(rename="github/release")] Release, } @@ -594,30 +597,6 @@ impl GitHubKind { } } -impl serde::Serialize for GitHubKind { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - serializer.serialize_str(self.as_str()) - } -} - -impl<'de> serde::Deserialize<'de> for GitHubKind { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - let s: &str = serde::Deserialize::deserialize(deserializer)?; - match s { - "github/repo" => Ok(GitHubKind::Repo), - "github/star" => Ok(GitHubKind::Star), - "github/release" => Ok(GitHubKind::Release), - _ => Err(serde::de::Error::custom(format!("Invalid kind: {}", s))), - } - } -} - #[cfg(test)] mod tests { use std::path::PathBuf;