From 63187649d8526658222d611f137633259712cc57 Mon Sep 17 00:00:00 2001 From: Raine Date: Sat, 14 Oct 2023 22:39:47 +0200 Subject: [PATCH] feat: custom debug impl for identifier --- pkgr/src/package/identifier.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pkgr/src/package/identifier.rs b/pkgr/src/package/identifier.rs index 3fde5e7..523b74b 100644 --- a/pkgr/src/package/identifier.rs +++ b/pkgr/src/package/identifier.rs @@ -1,7 +1,9 @@ use std::error::Error; +use std::fmt::Formatter; use std::str::FromStr; use regex::Regex; +use serde::Serializer; #[derive(Debug, Clone)] pub enum PackageIdentifierError { @@ -22,13 +24,31 @@ impl std::fmt::Display for PackageIdentifierError { impl Error for PackageIdentifierError {} -#[derive(Debug, Clone)] +#[derive(Clone)] pub enum PackageIdentifier { PackageLocator(PackageLocator), URI(String), Path(String), } +impl std::fmt::Debug for PackageIdentifier { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + if f.alternate() { + match self { + PackageIdentifier::PackageLocator(pl) => write!(f, "PackageLocator({:#?})", pl), + PackageIdentifier::URI(uri) => write!(f, "URI({:?})", uri), + PackageIdentifier::Path(path) => write!(f, "Path({:?})", path), + } + } else { + match self { + PackageIdentifier::PackageLocator(pl) => write!(f, "PL: {:?}", pl), + PackageIdentifier::URI(uri) => write!(f, "URI: {:?}", uri), + PackageIdentifier::Path(path) => write!(f, "Path: {:?}", path), + } + } + } +} + impl std::fmt::Display for PackageIdentifier { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self {