mantra_schema/
traces.rs

1use std::path::PathBuf;
2
3use crate::Line;
4
5use super::requirements::ReqId;
6
7#[derive(
8    Debug,
9    Clone,
10    Copy,
11    PartialEq,
12    Eq,
13    Hash,
14    serde::Serialize,
15    serde::Deserialize,
16    schemars::JsonSchema,
17)]
18pub struct LineSpan {
19    pub start: Line,
20    pub end: Line,
21}
22
23#[derive(
24    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
25)]
26pub struct TraceEntry {
27    pub ids: Vec<ReqId>,
28    /// The line the trace is defined
29    pub line: Line,
30    /// Optional span of lines this entry affects in the source.
31    ///
32    /// e.g. lines of a function body for a trace set at start of the function.
33    #[serde(alias = "line-span")]
34    pub line_span: Option<LineSpan>,
35    /// Optional name that is linked to this trace entry
36    #[serde(alias = "item-name")]
37    pub item_name: Option<String>,
38}
39
40impl std::fmt::Display for TraceEntry {
41    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42        write!(f, "req({}) at '{}'", self.ids.join(","), self.line)?;
43
44        if let Some(span) = self.line_span {
45            write!(f, " spans lines '{}:{}'", span.start, span.end)?;
46        }
47
48        Ok(())
49    }
50}
51
52#[derive(
53    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
54)]
55pub struct TraceSchema {
56    #[serde(serialize_with = "crate::serialize_schema_version")]
57    pub version: Option<String>,
58    pub traces: Vec<FileTraces>,
59}
60
61#[derive(
62    Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize, schemars::JsonSchema,
63)]
64pub struct FileTraces {
65    pub filepath: PathBuf,
66    pub traces: Vec<TraceEntry>,
67}