Skip to content

Commit d7c3500

Browse files
authored
Add Display impl for FieldNames (#4282)
Yet another step in my journey with this type Signed-off-by: Adam Gutglick <[email protected]>
1 parent bf52a05 commit d7c3500

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

vortex-dtype/src/dtype.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ pub type FieldName = Arc<str>;
2323
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2424
pub struct FieldNames(Arc<[FieldName]>);
2525

26+
impl Display for FieldNames {
27+
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
28+
write!(
29+
f,
30+
"[{}]",
31+
itertools::join(self.0.iter().map(|n| format!("\"{n}\"")), ", ")
32+
)
33+
}
34+
}
35+
2636
impl PartialEq<&FieldNames> for FieldNames {
2737
fn eq(&self, other: &&FieldNames) -> bool {
2838
self == *other
@@ -535,4 +545,12 @@ mod tests {
535545
assert_ne!(field_names, ["different", "fields", "here"]);
536546
assert_ne!(field_names, &["field1", "field2", "field3", "extra"][..]);
537547
}
548+
549+
#[test]
550+
fn test_field_names_display() {
551+
let names = FieldNames::from(["a", "b", "c"]);
552+
let f = format!("{names}");
553+
554+
assert_eq!(f, r#"["a", "b", "c"]"#);
555+
}
538556
}

0 commit comments

Comments
 (0)