use guess_host_triple::guess_host_triple; use platforms::{Platform as _Platform, PlatformReq}; use serde::Deserialize; use std::str::FromStr; #[derive(Debug, Deserialize)] pub struct Platform(String); impl Platform { pub fn new(p: impl Into) -> Self { Self(p.into()) } pub fn current() -> Platform { Self(guess_host_triple().unwrap_or("unknown").to_string()) } pub fn current_as_string() -> String { Self::current().into_string() } pub fn matches(&self, pf: impl AsRef) -> bool { match PlatformReq::from_str(pf.as_ref()) { Ok(p) => p.matches(&_Platform::find(&self.0).unwrap()), Err(_) => false, } } pub fn check(&self) -> bool { PlatformReq::from_str(&self.0).is_ok() } pub fn into_string(self) -> String { self.0 } pub fn any() -> Platform { Self(String::from("*")) } } impl Default for Platform { fn default() -> Self { Self::any() } }