static void generateEncoderVarData(
        final StringBuilder sb,
        final List<Token> tokens,
        final int level) throws IOException
    {
        for (int i = 0, size = tokens.size(); i < size; )
        {
            final Token varDataToken = tokens.get(i);
            if (varDataToken.signal() != Signal.BEGIN_VAR_DATA)
            {
                throw new IllegalStateException("tokens must begin with BEGIN_VAR_DATA: token=" + varDataToken);
            }

            final String characterEncoding = characterEncoding(tokens.get(i + 3).encoding());
            final String propertyName = toLowerSnakeCase(varDataToken.name());
            final Token lengthToken = tokens.get(i + 2);
            final Encoding lengthEncoding = lengthToken.encoding();
            final PrimitiveType lengthType = lengthEncoding.primitiveType();

            final String varDataType;
            final String toBytesFn;
            if (JavaUtil.isUtf8Encoding(characterEncoding))
            {
                varDataType = "&str";
                toBytesFn = ".as_bytes()";
            }
            else
            {
                varDataType = "&[u8]";
                toBytesFn = "";
            }

            // function to write slice ... todo - handle character encoding ?
            indent(sb, level, "/// VAR_DATA ENCODER - character encoding: '%s'\n", characterEncoding);
            indent(sb, level, "#[inline]\n");
            indent(sb, level, "pub fn %s(&mut self, value: %s) {\n", propertyName, varDataType);

            indent(sb, level + 1, "let limit = self.get_limit();\n");
            indent(sb, level + 1, "let data_length = value.len();\n");
            indent(sb, level + 1, "self.set_limit(limit + %d + data_length);\n", lengthType.size());

            indent(sb, level + 1,
                "self.get_buf_mut().put_%s_at(limit, data_length as %1$s);\n",
                rustTypeName(lengthType));

            indent(sb, level + 1, "self.get_buf_mut().put_slice_at(limit + %d, value%s);\n",
                lengthType.size(),
                toBytesFn);

            indent(sb, level, "}\n\n");

            i += varDataToken.componentTokenCount();
        }
    }
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