intel_crashlog/
metadata.rs1#[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#[derive(Default)]
17pub struct Metadata {
18 pub computer: Option<String>,
20 pub time: Option<Time>,
22 pub extra_cper_sections: Vec<CperSectionBody>,
25}
26
27pub 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}