Replacing One Type with Another - The bindgen User Guide
Description: `bindgen` automatically generates Rust FFI bindings to C and C++ libraries.

## Keyboard shortcuts

Press `←` or `→` to navigate between chapters

Press `S` or `/` to search in the book

Press `?` to show this help

Press `Esc` to hide this help

# Replacing One Type with Another

The `replaces` annotation can be used to use a type as a replacement for other (presumably more complex) type. This is used in Stylo to generate bindings for structures that for multiple reasons are too complex for bindgen to understand.

For example, in a C++ header:

    /**
     * <div rustbindgen replaces="nsTArray"></div>
     */
    template<typename T>
    class nsTArray_Simple {
      T* mBuffer;
    public:
      // The existence of a destructor here prevents bindgen from deriving the Clone
      // trait via a simple memory copy.
      ~nsTArray_Simple() {};
    };

That way, after code generation, the bindings for the `nsTArray` type are the ones that would be generated for `nsTArray_Simple`.

Replacing is only available as an annotation. To replace a C or C++ definition with a Rust definition, use blocklisting.