private static void generateEnum(
        final List<Token> enumTokens,
        final Appendable writer) throws IOException
    {
        final String originalEnumName = enumTokens.get(0).applicableTypeName();
        final String enumRustName = formatStructName(originalEnumName);
        final List<Token> messageBody = enumTokens.subList(1, enumTokens.size() - 1);
        if (messageBody.isEmpty())
        {
            throw new IllegalArgumentException("No valid values provided for enum " + originalEnumName);
        }

        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);

        for (final Token token : messageBody)
        {
            final Encoding encoding = token.encoding();
            final String literal = generateRustLiteral(encoding.primitiveType(), encoding.constValue().toString());
            indent(writer, 1, "%s = %s, \n", token.name(), literal);
        }

        // null value
        {
            final Encoding encoding = messageBody.get(0).encoding();
            final CharSequence nullVal = rustNullLiteral(encoding);
            indent(writer, 1, "#[default]\n");
            indent(writer, 1, "NullVal = %s, \n", nullVal);
        }
        indent(writer, 0, "}\n");

        // From impl
        generateFromPrimitiveForEnum(enumRustName, primitiveType, messageBody, writer);

        // Into impl
        generateFromEnumForPrimitive(enumRustName, primitiveType, messageBody, writer);

        // FromStr impl
        generateFromStrImplForEnum(enumRustName, messageBody, writer);

        // Display impl
        generateDisplayImplForEnum(enumRustName, primitiveType, messageBody, writer);
    }
Create a new Rust language {@link CodeGenerator}.

@param ir            for the messages and types.
@param crateVersion  for the generated crate.
@param outputManager for generating the codecs to.
sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/rust/RustGenerator.java