build_target/
vendor.rs

1use std::fmt;
2
3use crate::utils::{build_env, define_target_enum};
4
5define_target_enum! {
6    /// The vendor of the target platform, such as the manufacturer of the hardware or the provider of the operating system.
7    #[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
8    #[non_exhaustive]
9    pub enum Vendor {
10        /// Apple Inc.
11        Apple => "apple",
12        /// Fortanix SGX platform
13        Fortanix => "fortanix",
14        /// NVIDIA Corporation
15        Nvidia => "nvidia",
16        /// Generic PC platform
17        Pc => "pc",
18        /// Sony platform (e.g., PlayStation)
19        Sony => "sony",
20        /// Unknown or unspecified vendor
21        Unknown => "unknown",
22        /// Wind River Systems
23        Wrs => "wrs",
24        /// Universal Windows Platform
25        Uwp => "uwp",
26    }
27
28    as_str_doc = "String representing this target vendor which matches `#[cfg(target_vendor)]`",
29    from_str_doc = "Tries to parse the given string as an [`Vendor`] falling back to [`Vendor::Other`] for unknown values.",
30}
31
32impl Vendor {
33    /// Gets the current target [`Vendor`].
34    #[must_use]
35    pub fn target() -> Self {
36        Self::from_str(build_env("CARGO_CFG_TARGET_VENDOR"))
37    }
38}
39
40impl fmt::Display for Vendor {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        f.write_str(self.as_str())
43    }
44}