Skip to main content

cargo_fixit/ops/
check.rs

1use rustfix::diagnostics::Diagnostic;
2use serde::Deserialize;
3
4#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
5#[serde(untagged)]
6pub enum CheckOutput {
7    Artifact(Artifact),
8    Message(Message),
9}
10
11impl CheckOutput {
12    pub fn build_unit(&self) -> Option<&BuildUnit> {
13        match self {
14            Self::Artifact(a) => Some(&a.build_unit),
15            Self::Message(m) => Some(&m.build_unit),
16        }
17    }
18}
19
20#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
21#[allow(dead_code)]
22pub struct Artifact {
23    #[serde(flatten)]
24    pub build_unit: BuildUnit,
25    pub fresh: bool,
26}
27
28#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
29pub struct Message {
30    #[serde(flatten)]
31    pub build_unit: BuildUnit,
32    pub message: MessageDiagnostic,
33}
34
35#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq)]
36pub struct MessageDiagnostic {
37    #[serde(flatten)]
38    pub level: DiagnosticLevel,
39    #[serde(flatten)]
40    pub diagnostic: Diagnostic,
41}
42
43#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
44#[serde(tag = "level", rename_all = "lowercase")]
45pub enum DiagnosticLevel {
46    Error,
47    #[serde(other)]
48    Other,
49}
50
51#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
52pub struct BuildUnit {
53    pub package_id: String,
54    pub target: Target,
55}
56
57#[derive(Deserialize, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
58pub struct Target {
59    pub kind: Vec<TargetKind>,
60    pub crate_types: Vec<CrateType>,
61    pub name: String,
62    pub src_path: String,
63    pub edition: String,
64    pub doc: bool,
65    pub doctest: bool,
66    pub test: bool,
67}
68
69#[derive(Deserialize, Hash, PartialEq, Clone, Eq, Debug, PartialOrd, Ord)]
70#[serde(rename_all(deserialize = "kebab-case"))]
71pub enum TargetKind {
72    Bin,
73    Test,
74    Bench,
75    Example,
76    CustomBuild,
77    #[serde(untagged)]
78    Lib(CrateType),
79}
80
81#[derive(Deserialize, Hash, PartialEq, Clone, Eq, Debug, PartialOrd, Ord)]
82#[serde(rename_all(deserialize = "kebab-case"))]
83pub enum CrateType {
84    Bin,
85    Lib,
86    Rlib,
87    Dylib,
88    Cdylib,
89    Staticlib,
90    ProcMacro,
91    #[serde(untagged)]
92    Other(String),
93}