You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1021 B

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<String>) -> 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<str>) -> 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()
}
}