diff --git a/Cargo.lock b/Cargo.lock index 1b1c851..bd3484c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1972,31 +1972,6 @@ dependencies = [ "windows-targets", ] -[[package]] -name = "parse-display" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "287d8d3ebdce117b8539f59411e4ed9ec226e0a4153c7f55495c6070d68e6f72" -dependencies = [ - "parse-display-derive", - "regex", - "regex-syntax", -] - -[[package]] -name = "parse-display-derive" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc048687be30d79502dea2f623d052f3a074012c6eac41726b7ab17213616b1" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "regex-syntax", - "structmeta", - "syn 2.0.96", -] - [[package]] name = "parse-size" version = "1.1.0" @@ -3446,7 +3421,6 @@ dependencies = [ "daft", "expectorate", "hex", - "parse-display", "proptest", "regex", "schemars", diff --git a/Cargo.toml b/Cargo.toml index 6698921..3701723 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,6 @@ hubtools = { git = "https://github.com/oxidecomputer/hubtools.git", branch = "ma humantime = "2.1.0" indent_write = "2.2.0" itertools = "0.13.0" -parse-display = "0.10.0" parse-size = "1.1.0" predicates = "3.1.3" proptest = "1.5.0" diff --git a/artifact/Cargo.toml b/artifact/Cargo.toml index 2eb10f2..c0e8f99 100644 --- a/artifact/Cargo.toml +++ b/artifact/Cargo.toml @@ -12,7 +12,6 @@ schemars = ["dep:schemars"] [dependencies] daft.workspace = true hex.workspace = true -parse-display.workspace = true proptest = { workspace = true, optional = true } schemars = { workspace = true, optional = true } semver.workspace = true diff --git a/artifact/src/artifact.rs b/artifact/src/artifact.rs index 771763f..c910e6d 100644 --- a/artifact/src/artifact.rs +++ b/artifact/src/artifact.rs @@ -129,3 +129,17 @@ fn hex_schema( schema.format = Some(format!("hex string ({N} bytes)")); schema.into() } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn display_respects_padding() { + let h = ArtifactHash([0; 32]); + assert_eq!( + format!("{h:x>100}"), + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0000000000000000000000000000000000000000000000000000000000000000" + ); + } +} diff --git a/artifact/src/kind.rs b/artifact/src/kind.rs index c165611..1f750e8 100644 --- a/artifact/src/kind.rs +++ b/artifact/src/kind.rs @@ -5,9 +5,8 @@ use std::{borrow::Cow, convert::Infallible, fmt, str::FromStr}; use daft::Diffable; -use parse_display::{Display, FromStr}; use serde::{Deserialize, Serialize}; -use strum::{EnumIter, IntoEnumIterator}; +use strum::{Display, EnumIter, EnumString, IntoEnumIterator}; use thiserror::Error; /// The kind of artifact we are dealing with. @@ -168,13 +167,13 @@ impl FromStr for ArtifactKind { Ord, PartialOrd, Display, - FromStr, + EnumString, Deserialize, Serialize, EnumIter, )] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -#[display(style = "snake_case")] +#[strum(serialize_all = "snake_case")] #[serde(rename_all = "snake_case")] pub enum KnownArtifactKind { // Sled Artifacts @@ -289,4 +288,13 @@ mod tests { assert_eq!(kind, kind2); } } + + #[test] + fn display_respects_padding() { + let kind = ArtifactKind::from_static("foo"); + assert_eq!(format!("{kind:x>10}"), "xxxxxxxfoo"); + + let kind = KnownArtifactKind::Host; + assert_eq!(format!("{kind:x>10}"), "xxxxxxhost"); + } } diff --git a/artifact/src/version.rs b/artifact/src/version.rs index 94093e7..5478c7c 100644 --- a/artifact/src/version.rs +++ b/artifact/src/version.rs @@ -216,6 +216,12 @@ mod tests { ); } + #[test] + fn display_respects_padding() { + let v = ArtifactVersion::new_const("5.4.3"); + assert_eq!(format!("{v:x>10}"), "xxxxx5.4.3"); + } + #[proptest] fn proptest_valid_version(#[strategy(PROPTEST_REGEX)] version: String) { validate_version(&version).unwrap();