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:
committed by
Facebook GitHub Bot
parent
3c6a5c58f9
commit
bb936aaf0f
@@ -178,7 +178,7 @@ fn pack_platform_glob(
|
|||||||
let full_path = path::Path::new(&base_dir).join(&path);
|
let full_path = path::Path::new(&base_dir).join(&path);
|
||||||
if !full_path.exists() {
|
if !full_path.exists() {
|
||||||
bail!(error::Error::MissingPackFile(
|
bail!(error::Error::MissingPackFile(
|
||||||
platform.to_string(),
|
platform.clone(),
|
||||||
pack_type,
|
pack_type,
|
||||||
full_path,
|
full_path,
|
||||||
));
|
));
|
||||||
@@ -204,7 +204,7 @@ fn pack_platform_exact(
|
|||||||
let full_path = path::Path::new(&base_dir).join(f);
|
let full_path = path::Path::new(&base_dir).join(f);
|
||||||
if !full_path.exists() {
|
if !full_path.exists() {
|
||||||
bail!(error::Error::MissingPackFile(
|
bail!(error::Error::MissingPackFile(
|
||||||
platform.to_string(),
|
platform.clone(),
|
||||||
pack_type,
|
pack_type,
|
||||||
full_path,
|
full_path,
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -8,8 +8,22 @@
|
|||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
// TODO: Make this a newtype.
|
#[derive(Eq, PartialEq, Debug, PartialOrd, Ord, Clone, serde::Deserialize)]
|
||||||
pub type Platform = String;
|
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(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
|
|||||||
Reference in New Issue
Block a user