diff --git a/strum_macros/src/macros/strings/display.rs b/strum_macros/src/macros/strings/display.rs index b2f24d3a..2260b603 100644 --- a/strum_macros/src/macros/strings/display.rs +++ b/strum_macros/src/macros/strings/display.rs @@ -47,7 +47,7 @@ pub fn display_inner(ast: &syn::DeriveInput) -> TokenStream { Named(..) => quote! { {..} }, }; - arms.push(quote! { #name::#ident #params => f.write_str(#output) }); + arms.push(quote! { #name::#ident #params => f.pad(#output) }); } if arms.len() < variants.len() { diff --git a/strum_tests/tests/display.rs b/strum_tests/tests/display.rs index 3642f607..c36d6d2c 100644 --- a/strum_tests/tests/display.rs +++ b/strum_tests/tests/display.rs @@ -19,6 +19,14 @@ fn to_blue_string() { assert_eq!(String::from("blue"), format!("{}", Color::Blue { hue: 0 })); } +#[test] +fn test_formatters() { + assert_eq!(String::from(" blue"), format!("{:>6}", Color::Blue { hue: 0 })); + assert_eq!(String::from("blue "), format!("{:<6}", Color::Blue { hue: 0 })); + assert_eq!(String::from(" blue "), format!("{:^6}", Color::Blue { hue: 0 })); + assert_eq!(String::from("bl"), format!("{:.2}", Color::Blue { hue: 0 })); +} + #[test] fn to_yellow_string() { assert_eq!(String::from("yellow"), format!("{}", Color::Yellow));