forge_verify/
types.rs

1use eyre::Result;
2use serde::{Deserialize, Serialize};
3use std::{fmt, str::FromStr};
4
5/// Enum to represent the type of verification: `full` or `partial`.
6/// Ref: <https://docs.sourcify.dev/docs/full-vs-partial-match/>
7#[derive(Debug, Clone, clap::ValueEnum, Default, PartialEq, Eq, Serialize, Deserialize, Copy)]
8pub enum VerificationType {
9    #[default]
10    #[serde(rename = "full")]
11    Full,
12    #[serde(rename = "partial")]
13    Partial,
14}
15
16impl FromStr for VerificationType {
17    type Err = eyre::Error;
18
19    fn from_str(s: &str) -> Result<Self> {
20        match s {
21            "full" => Ok(Self::Full),
22            "partial" => Ok(Self::Partial),
23            _ => eyre::bail!("Invalid verification type"),
24        }
25    }
26}
27
28impl From<VerificationType> for String {
29    fn from(v: VerificationType) -> Self {
30        match v {
31            VerificationType::Full => "full".to_string(),
32            VerificationType::Partial => "partial".to_string(),
33        }
34    }
35}
36
37impl fmt::Display for VerificationType {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        match self {
40            Self::Full => write!(f, "full"),
41            Self::Partial => write!(f, "partial"),
42        }
43    }
44}