mod platforms;
#[cfg(feature = "std")]
mod req;
mod tier;
pub use self::tier::Tier;
#[cfg(feature = "std")]
pub use self::req::PlatformReq;
use self::platforms::ALL;
use crate::target::*;
use core::fmt;
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[non_exhaustive]
pub struct Platform {
pub target_triple: &'static str,
pub target_arch: Arch,
pub target_os: OS,
pub target_env: Env,
pub target_pointer_width: PointerWidth,
pub target_endian: Endian,
pub tier: Tier,
}
impl Platform {
pub const ALL: &'static [Platform] = ALL;
pub fn find(target_triple: &str) -> Option<&'static Platform> {
Self::ALL
.iter()
.find(|platform| platform.target_triple == target_triple)
}
}
impl fmt::Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.target_triple)
}
}
#[cfg(all(test, feature = "std"))]
mod tests {
use super::Platform;
use std::collections::HashSet;
#[test]
fn no_dupes_test() {
let mut target_triples = HashSet::new();
for platform in Platform::ALL {
assert!(
target_triples.insert(platform.target_triple),
"duplicate target triple: {}",
platform.target_triple
);
}
}
use std::collections::HashMap;
use super::*;
#[test]
#[ignore]
fn test_detection_feasibility() {
let mut all_platforms = HashMap::new();
for p in ALL {
if let Some(other_p) = all_platforms.insert(
(
p.target_arch,
p.target_os,
p.target_env,
p.target_endian,
p.target_pointer_width,
),
p.target_triple,
) {
panic!("{} and {} have identical properties, and cannot be distinguished based on properties alone", p.target_triple, other_p);
}
}
}
}