private static void generateEnumEncoder(
        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, "// skipping CONSTANT enum '%s'\n\n", name);
        }
        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(&mut self, value: %s) {\n", formatFunctionName(name), enumType);

            // NB: must create variable 'offset' before calling mutable self.get_buf_mut()
            indent(sb, level + 1, "let offset = self.%s;\n", getBufOffset(typeToken));
            indent(sb, level + 1, "self.get_buf_mut().put_%s_at(offset, value as %1$s)\n", rustPrimitiveType);
            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