#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
pub enum OutputFormat {
#[default]
Pdf,
Html,
}
impl std::str::FromStr for OutputFormat {
type Err = String;
fn from_str(s: &str) -> Result<Self, String> {
match s {
"pdf" => Ok(OutputFormat::Pdf),
"html" | "html-reflow" => Ok(OutputFormat::Html),
other => Err(format!("unknown --format {other:?} (expected pdf|html)")),
}
}
}
impl OutputFormat {
pub fn extension(self) -> &'static str {
match self {
OutputFormat::Pdf => "pdf",
OutputFormat::Html => "html",
}
}
pub(crate) fn cache_tag(self) -> &'static str {
match self {
OutputFormat::Pdf => "pdf",
OutputFormat::Html => "html-reflow",
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_html_cache_tag_is_not_the_removed_backends() {
assert_eq!(OutputFormat::Html.cache_tag(), "html-reflow");
assert_ne!(OutputFormat::Html.cache_tag(), "html");
assert_ne!(
OutputFormat::Pdf.cache_tag(),
OutputFormat::Html.cache_tag()
);
}
#[test]
fn html_fixed_no_longer_parses() {
assert!("html-fixed".parse::<OutputFormat>().is_err());
assert_eq!("html".parse::<OutputFormat>(), Ok(OutputFormat::Html));
assert_eq!(
"html-reflow".parse::<OutputFormat>(),
Ok(OutputFormat::Html)
);
}
}