Skip to main content

intel_crashlog/collateral/
pvss.rs

1// Copyright (C) 2025 Intel Corporation
2// SPDX-License-Identifier: MIT
3
4#[cfg(not(feature = "std"))]
5use alloc::{fmt, string::String};
6#[cfg(feature = "std")]
7use std::{fmt, path::PathBuf};
8
9/// A tuple of 4 strings that uniquely identifies a product.
10///
11/// Undefined elements of the tuples must be set to "all". For example: `XYZ/all/all/all`
12#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
13pub struct PVSS {
14    /// Product TLA
15    pub product: String,
16    /// Product variant
17    pub variant: String,
18    /// Product stepping
19    pub stepping: String,
20    /// Security level
21    pub security: String,
22}
23
24impl Default for PVSS {
25    fn default() -> Self {
26        PVSS {
27            product: "all".into(),
28            variant: "all".into(),
29            stepping: "all".into(),
30            security: "all".into(),
31        }
32    }
33}
34
35#[cfg(feature = "std")]
36impl From<&PVSS> for PathBuf {
37    fn from(pvss: &PVSS) -> Self {
38        [&pvss.product, &pvss.variant, &pvss.stepping, &pvss.security]
39            .iter()
40            .filter(|p| **p != "." && **p != "..")
41            .collect()
42    }
43}
44
45impl fmt::Display for PVSS {
46    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
47        write!(
48            f,
49            "{}/{}/{}/{}",
50            self.product, self.variant, self.stepping, self.security
51        )?;
52        Ok(())
53    }
54}