From 51db9b398bc16d05c0de2c0b33ce83d0943dec78 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Mon, 6 Jan 2025 18:17:35 +0000 Subject: [PATCH] Fix clippy warning --- src/source/github_authed_user.rs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/source/github_authed_user.rs b/src/source/github_authed_user.rs index bdcc88d..45d2cda 100644 --- a/src/source/github_authed_user.rs +++ b/src/source/github_authed_user.rs @@ -3,6 +3,7 @@ use anyhow::Result; use async_trait::async_trait; use octocrab::Octocrab; use serde::{Deserialize, Serialize}; +use std::fmt::Display; #[derive(Debug, Deserialize)] pub(crate) struct GithubAuthenticatedUser { @@ -73,23 +74,25 @@ struct Visibilities { visibility: Vec, } -impl ToString for Visibilities { - fn to_string(&self) -> String { +impl Display for Visibilities { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self.visibility.len() { - 1 => serde_variant::to_variant_name(&self.visibility[0]) - .unwrap() - .to_string(), + 1 => write!( + f, + "{}", + serde_variant::to_variant_name(&self.visibility[0]).unwrap() + ), 2 => { if self.visibility.contains(&Visibility::Private) && (self.visibility.contains(&Visibility::Private) || self.visibility.contains(&Visibility::Internal)) { - "both".to_string() + write!(f, "both") } else { - "".to_string() + write!(f, "") } } - _ => "".to_string(), + _ => write!(f, ""), } } } @@ -107,13 +110,15 @@ struct Affiliations { affiliation: Vec, } -impl ToString for Affiliations { - fn to_string(&self) -> String { - self.affiliation +impl Display for Affiliations { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let s = self + .affiliation .iter() .map(|i| serde_variant::to_variant_name(i).unwrap()) .collect::>() - .join(",") + .join(","); + write!(f, "{}", s) } }