Repository: Peternator7/strum (rust)

Issue:
strum::Display doesn't work with non-unit non-string variants
strum::Display and #[strum(default)] doesn't work with non-unit non-string variants.   It should probably try to convert the enclosed tuple into a string?

```
#[derive(strum::Display)]
enum Color {
    Red,
    Blue,
    Green,
}
#[derive(strum::Display)]   <---- this fails: Mismatched types.
enum TestEnum {
    #[strum(default)]
    Color(Color),
}
```

Pull request description:
Fix "Display" for non string Defaults
fixes #306 

Patch:
diff --git a/strum_macros/src/macros/strings/display.rs b/strum_macros/src/macros/strings/display.rs
index fcc5936..77f8afa 100644
--- a/strum_macros/src/macros/strings/display.rs
+++ b/strum_macros/src/macros/strings/display.rs
@@ -35,7 +35,7 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
         if variant_properties.to_string.is_none() && variant_properties.default.is_some() {
             match &variant.fields {
                 Fields::Unnamed(fields) if fields.unnamed.len() == 1 => {
-                    arms.push(quote! { #name::#ident(ref s) => f.pad(s) });
+                    arms.push(quote! { #name::#ident(ref s) => s.fmt(f) });
                 }
                 _ => {
                     return Err(syn::Error::new_spanned(
@@ -45,7 +45,7 @@ pub fn display_inner(ast: &DeriveInput) -> syn::Result<TokenStream> {
                 }
             }
         } else {
-            arms.push(quote! { #name::#ident #params => f.pad(#output) });
+            arms.push(quote! { #name::#ident #params => (#output).fmt(f) } );
         }
     }
 


Test patch:
diff --git a/strum_tests/tests/display.rs b/strum_tests/tests/display.rs
index 4cec148..77ea25c 100644
--- a/strum_tests/tests/display.rs
+++ b/strum_tests/tests/display.rs
@@ -1,8 +1,8 @@
-use strum::{Display, EnumString};
+use strum::EnumString;
 
 mod core {} // ensure macros call `::core`
 
-#[derive(Debug, Eq, PartialEq, EnumString, Display)]
+#[derive(Debug, Eq, PartialEq, EnumString, strum::Display)]
 enum Color {
     #[strum(to_string = "RedRed")]
     Red,
@@ -49,12 +49,12 @@ fn to_red_string() {
 #[test]
 fn to_green_string() {
     assert_eq!(
-        String::from("lime"),
-        format!("{}", Color::Green("lime".into()))
+        String::from("  lime"),
+        format!("{:>6}", Color::Green("lime".into()))
     );
 }
 
-#[derive(Debug, Eq, PartialEq, EnumString, Display)]
+#[derive(Debug, Eq, PartialEq, EnumString, strum::Display)]
 enum ColorWithDefaultAndToString {
     #[strum(default, to_string = "GreenGreen")]
     Green(String),
@@ -68,7 +68,7 @@ fn to_green_with_default_and_to_string() {
     );
 }
 
-#[derive(Display, Debug, Eq, PartialEq)]
+#[derive(strum::Display, Debug, Eq, PartialEq)]
 #[strum(serialize_all = "snake_case")]
 enum Brightness {
     DarkBlack,
@@ -94,3 +94,18 @@ fn brightness_to_string() {
         Brightness::BrightWhite.to_string().as_ref()
     );
 }
+
+#[derive(strum::Display, Debug, Eq, PartialEq)]
+#[strum(serialize_all = "snake_case")]
+enum NonStringDefault {
+    #[strum(default)]
+    Number(usize),
+}
+
+#[test]
+fn non_string_default_to_string() {
+    assert_eq!(
+        String::from("0014"),
+        format!("{:04}", NonStringDefault::Number(14))
+    );
+}