@Override
    public void generate() throws IOException
    {
        // create Cargo.toml
        try (Writer writer = outputManager.createCargoToml())
        {
            final String packageName = toLowerSnakeCase(ir.packageName()).replaceAll("[.-]", "_");
            final String namespace;
            if (ir.namespaceName() == null || ir.namespaceName().equalsIgnoreCase(packageName))
            {
                namespace = packageName.toLowerCase();
            }
            else
            {
                namespace = (ir.namespaceName() + "_" + packageName).toLowerCase();
            }

            indent(writer, 0, "[package]\n");
            indent(writer, 0, "name = \"%s\"\n", namespace);
            indent(writer, 0, "version = \"%s\"\n", crateVersion);
            indent(writer, 0, "authors = [\"sbetool\"]\n");
            indent(writer, 0, "description = \"%s\"\n", ir.description());
            indent(writer, 0, "edition = \"2021\"\n\n");
            indent(writer, 0, "[lib]\n");
            indent(writer, 0, "name = \"%s\"\n", namespace);
            indent(writer, 0, "path = \"src/lib.rs\"\n");
        }

        // lib.rs
        final LibRsDef libRsDef = new LibRsDef(outputManager, ir.byteOrder(), schemaVersionType());

        generateEnums(ir, outputManager);
        generateBitSets(ir, outputManager);
        generateComposites(schemaVersionType(), ir, outputManager);

        for (final List<Token> tokens : ir.messages())
        {
            final Token msgToken = tokens.get(0);
            final String codecModName = codecModName(msgToken.name());
            final List<Token> messageBody = tokens.subList(1, tokens.size() - 1);

            int i = 0;
            final List<Token> fields = new ArrayList<>();
            i = collectFields(messageBody, i, fields);

            final List<Token> groups = new ArrayList<>();
            i = collectGroups(messageBody, i, groups);

            final List<Token> varData = new ArrayList<>();
            collectVarData(messageBody, i, varData);

            try (Writer out = outputManager.createOutput(codecModName))
            {
                indent(out, 0, "use crate::*;\n\n");
                indent(out, 0, "pub use decoder::%sDecoder;\n", formatStructName(msgToken.name()));
                indent(out, 0, "pub use encoder::%sEncoder;\n\n", formatStructName(msgToken.name()));

                indent(out, 0, "pub use crate::SBE_SCHEMA_ID;\n");
                indent(out, 0, "pub use crate::SBE_SCHEMA_VERSION;\n");
                indent(out, 0, "pub use crate::SBE_SEMANTIC_VERSION;\n\n");

                final String blockLengthType = blockLengthType();
                final String templateIdType = rustTypeName(ir.headerStructure().templateIdType());
                indent(out, 0, "pub const SBE_BLOCK_LENGTH: %s = %d;\n", blockLengthType, msgToken.encodedLength());
                indent(out, 0, "pub const SBE_TEMPLATE_ID: %s = %d;\n\n", templateIdType, msgToken.id());

                MessageCoderDef.generateEncoder(ir, out, msgToken, fields, groups, varData);
                MessageCoderDef.generateDecoder(ir, out, msgToken, fields, groups, varData);
            }
        }

        libRsDef.generate(ir);
    }
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