Repository: not-fl3/nanoserde (rust)

Issue:
Unamed variants issue on complex enums
For example:
```rust
#[derive(DeRon, SerRon)]
pub enum SlashMode {
    Bounce = 0x10,
    Slash = 0x12,
    Loading = 0x13,
    BitStream = 0x1d,
    Transmission = 0x1a,
    Flow = 0x19,
    Flux = 0x25,
    Phantom = 0x24,
    Spectrum = 0x26,
    Hazard = 0x32,
    Interfacing = 0x33,
    Ramp = 0x34,
    GameOver = 0x42,
    Start = 0x43,
    Buzzer = 0x44,
}
```
I have additional derives that are required and the zbus ones in particular which enforce the `name = value` constraint. But that makes the `Unamed variants are not supported` error a little confusing.

This effectively prevents me moving off `serde`. Is there any other information I can provide?

Pull request description:
Support Enum numbered variant parsing
Allows ser/de of enums such as:

```rust
pub enum Fud {
    A = 0,
    B = 1,
    C = 2,
}
```

Should close #101

Patch:
diff --git a/derive/src/parse.rs b/derive/src/parse.rs
index f027a75..2ac4ee1 100644
--- a/derive/src/parse.rs
+++ b/derive/src/parse.rs
@@ -1232,6 +1232,12 @@ fn next_enum<T: Iterator<Item = TokenTree> + Clone>(mut source: &mut Peekable<T>
             break;
         }
 
+        if next_exact_punct(&mut body, "=").is_some() {
+            body.next();
+            let _maybe_coma = next_exact_punct(&mut body, ",");
+            continue;
+        }
+
         let attributes = next_attributes_list(&mut body);
 
         let variant_name = next_ident(&mut body).expect("Unnamed variants are not supported");
@@ -1260,6 +1266,7 @@ fn next_enum<T: Iterator<Item = TokenTree> + Clone>(mut source: &mut Peekable<T>
                 vis: Visibility::Public,
             });
         }
+
         let _maybe_semicolon = next_exact_punct(&mut body, ";");
         let _maybe_coma = next_exact_punct(&mut body, ",");
     }


Test patch:
diff --git a/tests/json.rs b/tests/json.rs
index 41ce1b1..21e3e45 100644
--- a/tests/json.rs
+++ b/tests/json.rs
@@ -631,6 +631,37 @@ fn de_enum() {
 
 #[test]
 fn de_ser_enum() {
+    #[derive(DeJson, SerJson, PartialEq, Debug)]
+    pub enum Fud {
+        A = 0,
+        B = 1,
+        C = 2,
+    }
+
+    #[derive(DeJson, SerJson, PartialEq, Debug)]
+    pub struct Bar {
+        foo1: Fud,
+        foo2: Fud,
+        foo3: Fud,
+    }
+
+    let json = "{\"foo1\":\"A\",\"foo2\":\"B\",\"foo3\":\"C\"}";
+
+    let data = Bar {
+        foo1: Fud::A,
+        foo2: Fud::B,
+        foo3: Fud::C,
+    };
+
+    let serialized = SerJson::serialize_json(&data);
+    assert_eq!(serialized, json);
+
+    let deserialized: Bar = DeJson::deserialize_json(&serialized).unwrap();
+    assert_eq!(deserialized, data);
+}
+
+#[test]
+fn de_ser_enum_complex() {
     #[derive(DeJson, SerJson, PartialEq, Debug)]
     pub enum Foo {
         A,
diff --git a/tests/ron.rs b/tests/ron.rs
index c71ae6f..728e768 100644
--- a/tests/ron.rs
+++ b/tests/ron.rs
@@ -380,6 +380,70 @@ fn de_enum() {
     );
 }
 
+#[test]
+fn de_ser_enum() {
+    #[derive(SerRon, DeRon, PartialEq, Debug)]
+    pub enum Fud {
+        A = 0,
+        B = 1,
+        C = 2,
+    }
+
+    #[derive(SerRon, DeRon, PartialEq, Debug)]
+    pub struct Bar {
+        foo1: Fud,
+        foo2: Fud,
+        foo3: Fud,
+    }
+
+    let ron = "(\n    foo1:A,\n    foo2:B,\n    foo3:C,\n)";
+
+    let data = Bar {
+        foo1: Fud::A,
+        foo2: Fud::B,
+        foo3: Fud::C,
+    };
+    let serialized = SerRon::serialize_ron(&data);
+
+    assert_eq!(serialized, ron);
+
+    let deserialized: Bar = DeRon::deserialize_ron(&serialized).unwrap();
+    assert_eq!(deserialized, data);
+}
+
+#[test]
+fn ser_enum_complex() {
+    #[derive(SerRon, DeRon, PartialEq, Debug)]
+    pub enum Foo {
+        A,
+        B(i32, String),
+        C { a: i32, b: String },
+    }
+
+    #[derive(SerRon, DeRon, PartialEq, Debug)]
+    pub struct Bar {
+        foo1: Foo,
+        foo2: Foo,
+        foo3: Foo,
+    }
+
+    let ron = "(\n    foo1:A,\n    foo2:B(1, \"asd\"),\n    foo3:C(\n        a:2,\n        b:\"qwe\",\n    ),\n)";
+
+    let data = Bar {
+        foo1: Foo::A,
+        foo2: Foo::B(1, String::from("asd")),
+        foo3: Foo::C {
+            a: 2,
+            b: String::from("qwe"),
+        },
+    };
+    let serialized = SerRon::serialize_ron(&data);
+    assert_eq!(serialized, ron);
+
+    let deserialized: Bar = DeRon::deserialize_ron(&serialized).unwrap();
+    assert_eq!(deserialized, data);
+}
+
 #[test]
 fn test_various_escapes() {
     let ron = r#""\n\t\u0020\f\b\\\"\/\ud83d\uDE0B\r""#;