Skip to content

Commit

Permalink
[Rust] updated RustGenerator::generateEnum() to support derive "Defau…
Browse files Browse the repository at this point in the history
…lt" instead of generating impl
  • Loading branch information
Michael Ward committed Aug 4, 2023
1 parent 6b993b8 commit 08ce8c2
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1195,7 +1195,7 @@ private static void generateEnum(
throw new IllegalArgumentException("No valid values provided for enum " + originalEnumName);
}

indent(writer, 0, "#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]\n");
indent(writer, 0, "#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]\n");
final String primitiveType = rustTypeName(messageBody.get(0).encoding().primitiveType());
indent(writer, 0, "#[repr(%s)]\n", primitiveType);
indent(writer, 0, "pub enum %s {\n", enumRustName);
Expand All @@ -1212,16 +1212,11 @@ private static void generateEnum(
final Encoding encoding = messageBody.get(0).encoding();
final CharSequence nullVal = generateRustLiteral(encoding.primitiveType(),
encoding.applicableNullValue().toString());
indent(writer, 1, "#[default]\n");
indent(writer, 1, "NullVal = %s, \n", nullVal);
}
indent(writer, 0, "}\n");

// Default implementation to support Default in other structs
indent(writer, 0, "impl Default for %s {\n", enumRustName);
indent(writer, 1, "#[inline]\n");
indent(writer, 1, "fn default() -> Self { %s::%s }\n", enumRustName, "NullVal");
indent(writer, 0, "}\n");

// From impl
indent(writer, 0, "impl From<%s> for %s {\n", primitiveType, enumRustName);
indent(writer, 1, "#[inline]\n");
Expand Down

0 comments on commit 08ce8c2

Please sign in to comment.