Skip to content

Commit

Permalink
fix(GitHubKind): do no reimplement (de)serialization, relying on serd…
Browse files Browse the repository at this point in the history
…e instead
  • Loading branch information
cedi committed Nov 29, 2024
1 parent d216b10 commit abbc79f
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions src/helpers/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -594,30 +597,6 @@ impl GitHubKind {
}
}

impl serde::Serialize for GitHubKind {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(self.as_str())
}
}

impl<'de> serde::Deserialize<'de> for GitHubKind {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
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;
Expand Down

0 comments on commit abbc79f

Please sign in to comment.