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
6#[cfg(not(feature = "std"))]
7use alloc::vec::Vec;
8#[cfg(not(feature = "std"))]
9use alloc::{fmt, string::String};
10#[cfg(feature = "std")]
11use std::fmt;
12
13use crate::cper::CperSectionBody;
14
15/// Crash Log Metadata
16#[derive(Default)]
17pub struct Metadata {
18    /// Name of the computer where the Crash Log has been extracted from.
19    pub computer: Option<String>,
20    /// Time of the extraction
21    pub time: Option<Time>,
22    /// When the Crash Log is extracted from a CPER, this field stores the extra CPER sections that
23    /// could be read from the CPER structure.
24    pub extra_cper_sections: Vec<CperSectionBody>,
25}
26
27/// Crash Log Extraction Time
28pub struct Time {
29    pub year: u16,
30    pub month: u8,
31    pub day: u8,
32    pub hour: u8,
33    pub minute: u8,
34}
35
36impl fmt::Display for Metadata {
37    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
38        match (self.computer.as_ref(), self.time.as_ref()) {
39            (Some(computer), Some(time)) => write!(f, "{computer}-{time}"),
40            (None, Some(time)) => write!(f, "{time}"),
41            (Some(computer), None) => write!(f, "{computer}"),
42            (None, None) => write!(f, "unnamed"),
43        }
44    }
45}
46
47impl fmt::Display for Time {
48    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49        write!(
50            f,
51            "{:04}-{:02}-{:02}-{:02}-{:02}",
52            self.year, self.month, self.day, self.hour, self.minute
53        )
54    }
55}