Skip to main content

intel_crashlog/
metadata.rs

1// Copyright (C) 2025 Intel Corporation
2// SPDX-License-Identifier: MIT
3
4//! Information extracted alongside the Crash Log records.
5
6mod time;
7
8#[cfg(not(feature = "std"))]
9use alloc::vec::Vec;
10#[cfg(not(feature = "std"))]
11use alloc::{fmt, string::String};
12#[cfg(feature = "std")]
13use std::fmt;
14
15use crate::cper::CperSectionBody;
16use crate::source::CrashLogSource;
17
18pub use time::Time;
19
20/// Crash Log Metadata
21#[derive(Default, Clone)]
22pub struct Metadata {
23    /// Name of the computer where the Crash Log has been extracted from.
24    pub computer: Option<String>,
25    /// Name of the source where the Crash Log has been extracted from.
26    pub source: Option<CrashLogSource>,
27    /// Time of the extraction
28    pub time: Option<Time>,
29    /// When the Crash Log is extracted from a CPER, this field stores the extra CPER sections that
30    /// could be read from the CPER structure.
31    pub extra_cper_sections: Vec<CperSectionBody>,
32}
33
34impl fmt::Display for Metadata {
35    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
36        let mut sep = "";
37
38        if let Some(computer) = &self.computer {
39            write!(f, "{computer}")?;
40            sep = "-";
41        }
42
43        if let Some(source) = &self.source {
44            write!(f, "{sep}{source}")?;
45            sep = "-";
46        }
47
48        if let Some(time) = &self.time {
49            write!(f, "{sep}{time}")?;
50            sep = "-";
51        }
52
53        if sep.is_empty() {
54            write!(f, "unnamed")?;
55        }
56
57        Ok(())
58    }
59}