use std::fmt;
use crate::models::database::LicenseType;
use crate::models::download::Outcome;
use crate::models::{DatabaseFormat, Standing};
macro_rules! wire_spelling {
($type:ty { $($variant:ident => $wire:literal),+ $(,)? }) => {
impl $type {
pub fn as_str(&self) -> &str {
match self {
$(Self::$variant => $wire,)+
Self::Other(value) => value,
}
}
}
impl fmt::Display for $type {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
};
}
wire_spelling!(DatabaseFormat { Csvgz => "csvgz", Mmdb => "mmdb" });
wire_spelling!(Standing {
Licensed => "licensed",
Expired => "expired",
Unlicensed => "unlicensed",
});
wire_spelling!(LicenseType {
Evaluation => "evaluation",
Standard => "standard",
Redistribute => "redistribute",
});
wire_spelling!(Outcome {
Ok => "ok",
Unauthorized => "unauthorized",
Denied => "denied",
Expired => "expired",
Unknown => "unknown",
Unavailable => "unavailable",
});
impl From<&DatabaseFormat> for DatabaseFormat {
fn from(format: &DatabaseFormat) -> Self {
format.clone()
}
}