firedbg-protocol 1.0.0

FireDBG Event Stream Protocol
Documentation
//! Definition of SourceFile

use serde::{Deserialize, Serialize};
use std::time::SystemTime;

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
/// Source File
pub struct SourceFile {
    /// 0 is unused
    pub id: u32,
    pub path: String,
    pub crate_name: String,
    pub modified: SystemTime,
    // TODO: SHA-1 hash generated by `git hash-object <PATH>`
    // pub hash: String,
}

#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
/// Line number of column of a symbol.
pub struct LineColumn {
    pub line: u32,
    pub column: Option<u32>,
}

impl Default for SourceFile {
    fn default() -> Self {
        Self {
            id: Default::default(),
            path: Default::default(),
            crate_name: Default::default(),
            modified: SystemTime::UNIX_EPOCH,
        }
    }
}

impl SourceFile {
    pub fn redacted(&mut self) {
        let path = std::path::Path::new(&self.path);
        let file_name = path.file_name().expect("file").to_str().expect("str");
        self.path = format!("<redacted>/{file_name}");

        self.modified = SystemTime::UNIX_EPOCH;
    }
}