firedbg_protocol/
source.rs

1//! Definition of SourceFile
2
3use serde::{Deserialize, Serialize};
4use std::time::SystemTime;
5
6#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
7/// Source File
8pub struct SourceFile {
9    /// 0 is unused
10    pub id: u32,
11    pub path: String,
12    pub crate_name: String,
13    pub modified: SystemTime,
14    // TODO: SHA-1 hash generated by `git hash-object <PATH>`
15    // pub hash: String,
16}
17
18#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
19/// Line number of column of a symbol.
20pub struct LineColumn {
21    pub line: u32,
22    pub column: Option<u32>,
23}
24
25impl Default for SourceFile {
26    fn default() -> Self {
27        Self {
28            id: Default::default(),
29            path: Default::default(),
30            crate_name: Default::default(),
31            modified: SystemTime::UNIX_EPOCH,
32        }
33    }
34}
35
36impl SourceFile {
37    pub fn redacted(&mut self) {
38        let path = std::path::Path::new(&self.path);
39        let file_name = path.file_name().expect("file").to_str().expect("str");
40        self.path = format!("<redacted>/{file_name}");
41
42        self.modified = SystemTime::UNIX_EPOCH;
43    }
44}