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