private static void generateEnumDecoder(
        final StringBuilder sb,
        final int level,
        final Token fieldToken,
        final Token typeToken,
        final String name) throws IOException
    {
        final String referencedName = typeToken.referencedName();
        final String enumType = format("%s::%s",
            toLowerSnakeCase(referencedName == null ? typeToken.name() : referencedName),
            formatStructName(referencedName == null ? typeToken.name() : referencedName));

        if (fieldToken.isConstantEncoding())
        {
            indent(sb, level, "/// CONSTANT enum\n");
            final Encoding encoding = fieldToken.encoding();
            final String rawConstValueName = encoding.constValue().toString();
            final int indexOfDot = rawConstValueName.indexOf('.');
            final String constValueName = -1 == indexOfDot ?
                rawConstValueName :
                rawConstValueName.substring(indexOfDot + 1);

            final String constantRustExpression = enumType + "::" + constValueName;
            appendConstAccessor(sb, name, enumType, constantRustExpression, level);
        }
        else
        {
            final Encoding encoding = typeToken.encoding();
            final String rustPrimitiveType = rustTypeName(encoding.primitiveType());

            indent(sb, level, "/// REQUIRED enum\n");
            indent(sb, level, "#[inline]\n");
            indent(sb, level, "pub fn %s(&self) -> %s {\n", formatFunctionName(name), enumType);

            if (fieldToken.version() > 0)
            {
                indent(sb, level + 1, "if self.acting_version() < %d {\n", fieldToken.version());
                indent(sb, level + 2, "return %s::default();\n", enumType);
                indent(sb, level + 1, "}\n\n");
            }

            indent(sb, level + 1, "self.get_buf().get_%s_at(self.%s).into()\n",
                rustPrimitiveType,
                getBufOffset(typeToken));
            indent(sb, level, "}\n\n");
        }
    }
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