Skip to content

Commit

Permalink
Remove as_string and move impl into Display
Browse files Browse the repository at this point in the history
Whith Display, the `to_string` is auto-generated
  • Loading branch information
eikek committed Jul 17, 2024
1 parent 1633930 commit 121e851
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/util/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@ pub enum ProjectId {
FullUrl(Url),
}

impl ProjectId {
pub fn as_string(&self) -> String {
match self {
ProjectId::NamespaceSlug { namespace, slug } => {
format!("{}/{}", namespace, slug)
}
ProjectId::Id(id) => id.to_string(),
ProjectId::FullUrl(url) => url.to_string(),
}
}
}

#[derive(Debug, PartialEq, Snafu)]
pub enum ProjectIdParseError {
UrlParse { source: UrlParseError },
Expand All @@ -50,7 +38,17 @@ impl str::FromStr for ProjectId {

impl fmt::Display for ProjectId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.as_string())
write!(
f,
"{}",
match self {
ProjectId::NamespaceSlug { namespace, slug } => {
format!("{}/{}", namespace, slug)
}
ProjectId::Id(id) => id.to_string(),
ProjectId::FullUrl(url) => url.to_string(),
}
)
}
}

Expand Down

0 comments on commit 121e851

Please sign in to comment.