feat: custom debug impl for identifier

This commit is contained in:
Didier Slof 2023-08-07 04:27:02 +02:00
parent b8df4fd15b
commit d898370d82
Signed by: didier
GPG key ID: 01E71F18AA4398E5

View file

@ -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 {