Make Platform a newtype

Summary:
Just a bit of extra type safety. The previous diff caused a bit of a regression
by making things stringly-typed.

Reviewed By: lblasa

Differential Revision: D35902107

fbshipit-source-id: a599106f899ec3d205663b5791420aee29f3eeae
This commit is contained in:
Pascal Hartig
2022-04-26 03:29:40 -07:00
committed by Facebook GitHub Bot
parent 3c6a5c58f9
commit bb936aaf0f
2 changed files with 18 additions and 4 deletions

View File

@@ -178,7 +178,7 @@ fn pack_platform_glob(
let full_path = path::Path::new(&base_dir).join(&path);
if !full_path.exists() {
bail!(error::Error::MissingPackFile(
platform.to_string(),
platform.clone(),
pack_type,
full_path,
));
@@ -204,7 +204,7 @@ fn pack_platform_exact(
let full_path = path::Path::new(&base_dir).join(f);
if !full_path.exists() {
bail!(error::Error::MissingPackFile(
platform.to_string(),
platform.clone(),
pack_type,
full_path,
));

View File

@@ -8,8 +8,22 @@
use std::fmt::{self, Display};
use std::str;
// TODO: Make this a newtype.
pub type Platform = String;
#[derive(Eq, PartialEq, Debug, PartialOrd, Ord, Clone, serde::Deserialize)]
pub struct Platform(pub String);
impl str::FromStr for Platform {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Platform(s.to_string()))
}
}
impl Display for Platform {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(
Debug,