diff --git a/packer/src/main.rs b/packer/src/main.rs index 931836d6c..1cdd58dae 100644 --- a/packer/src/main.rs +++ b/packer/src/main.rs @@ -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, )); diff --git a/packer/src/types.rs b/packer/src/types.rs index c88ca662b..ce4656e78 100644 --- a/packer/src/types.rs +++ b/packer/src/types.rs @@ -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 { + Ok(Platform(s.to_string())) + } +} + +impl Display for Platform { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} #[derive( Debug,