private static void generatePrimitiveOptionalDecoder(
        final StringBuilder sb,
        final int level,
        final Token fieldToken,
        final String name,
        final Encoding encoding) throws IOException
    {
        assert encoding.presence() == Encoding.Presence.OPTIONAL;
        final PrimitiveType primitiveType = encoding.primitiveType();
        final String rustPrimitiveType = rustTypeName(primitiveType);
        final String characterEncoding = encoding.characterEncoding();
        indent(sb, level, "/// primitive field - '%s' { null_value: '%s' }\n",
            encoding.presence(), rustNullLiteral(encoding));

        if (characterEncoding != null)
        {
            // ASCII and UTF-8
            indent(sb, level, "/// characterEncoding: '%s'\n", characterEncoding);
        }

        indent(sb, level, "#[inline]\n");
        indent(sb, level, "pub fn %s(&self) -> Option<%s> {\n",
            formatFunctionName(name),
            rustPrimitiveType);

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

        indent(sb, level + 1, "let value = self.get_buf().get_%s_at(self.%s);\n",
            rustPrimitiveType,
            getBufOffset(fieldToken));

        final String nullLiteral = rustNullLiteral(encoding);
        if (nullLiteral.endsWith("::NAN"))
        {
            indent(sb, level + 1, "if value.is_nan() {\n");
        }
        else
        {
            indent(sb, level + 1, "if value == %s {\n", nullLiteral);
        }

        indent(sb, level + 2, "None\n");
        indent(sb, level + 1, "} else {\n");
        indent(sb, level + 2, "Some(value)\n");
        indent(sb, level + 1, "}\n");
        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