private static void generateCompositeEncoder(
        final List<Token> tokens,
        final String encoderName,
        final Writer out) throws IOException
    {
        indent(out, 0, "pub mod encoder {\n");
        indent(out, 1, "use super::*;\n\n");

        // define struct...
        indent(out, 1, "#[derive(Debug, Default)]\n");
        indent(out, 1, "pub struct %s<P> {\n", encoderName);
        indent(out, 2, "parent: Option<P>,\n");
        indent(out, 2, "offset: usize,\n");
        indent(out, 1, "}\n\n");

        appendImplWriterForComposite(out, 1, encoderName);

        // impl<'a> start
        indent(out, 1, "impl<'a, P> %s<P> where P: Writer<'a> + Default {\n", encoderName);
        indent(out, 2, "pub fn wrap(mut self, parent: P, offset: usize) -> Self {\n");
        indent(out, 3, "self.parent = Some(parent);\n");
        indent(out, 3, "self.offset = offset;\n");
        indent(out, 3, "self\n");
        indent(out, 2, "}\n\n");

        // parent fn...
        indent(out, 2, "#[inline]\n");
        indent(out, 2, "pub fn parent(&mut self) -> SbeResult<P> {\n");
        indent(out, 3, "self.parent.take().ok_or(SbeErr::ParentNotSet)\n");
        indent(out, 2, "}\n\n");

        for (int i = 1, end = tokens.size() - 1; i < end; )
        {
            final Token encodingToken = tokens.get(i);
            final StringBuilder sb = new StringBuilder();

            switch (encodingToken.signal())
            {
                case ENCODING:
                    generatePrimitiveEncoder(sb, 2, encodingToken, encodingToken.name());
                    break;
                case BEGIN_ENUM:
                    generateEnumEncoder(sb, 2, encodingToken, encodingToken, encodingToken.name());
                    break;
                case BEGIN_SET:
                    generateBitSetEncoder(sb, 2, encodingToken, encodingToken.name());
                    break;
                case BEGIN_COMPOSITE:
                    generateCompositeEncoder(sb, 2, encodingToken, encodingToken.name());
                    break;
                default:
                    break;
            }

            out.append(sb);
            i += encodingToken.componentTokenCount();
        }

        indent(out, 1, "}\n"); // end impl
        indent(out, 0, "} // end encoder mod \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