ephemeris_report/
format.rs1use std::fs;
2use std::path::Path;
3
4use facet::Facet;
5
6use crate::{ConvertError, Converted, clippy, diff, junit};
7
8#[derive(Clone, Copy, Debug, Eq, Facet, PartialEq)]
10#[facet(rename_all = "lowercase")]
11#[repr(u8)]
12pub enum Format {
13 Junit,
15 Clippy,
17 Diff,
19}
20
21impl Format {
22 #[must_use]
24 pub const fn attachment(self) -> &'static str {
25 match self {
26 Self::Junit => "junit.xml",
27 Self::Clippy => "clippy.json",
28 Self::Diff => "diff.txt",
29 }
30 }
31
32 pub fn convert(self, native: &[u8], root: &Path) -> Result<Converted, ConvertError> {
39 match self {
40 Self::Junit => junit::convert(native),
41 Self::Clippy => clippy::convert(native),
42 Self::Diff => {
43 let root = fs::canonicalize(root).unwrap_or_else(|_| root.to_path_buf());
44 diff::convert(native, &root)
45 }
46 }
47 }
48}