• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Replacing One Type with Another
2
3The `replaces` annotation can be used to use a type as a replacement for other
4(presumably more complex) type. This is used in Stylo to generate bindings for
5structures that for multiple reasons are too complex for bindgen to understand.
6
7For example, in a C++ header:
8
9```cpp
10/**
11 * <div rustbindgen replaces="nsTArray"></div>
12 */
13template<typename T>
14class nsTArray_Simple {
15  T* mBuffer;
16public:
17  // The existence of a destructor here prevents bindgen from deriving the Clone
18  // trait via a simple memory copy.
19  ~nsTArray_Simple() {};
20};
21```
22
23That way, after code generation, the bindings for the `nsTArray` type are
24the ones that would be generated for `nsTArray_Simple`.
25
26Replacing is only available as an annotation. To replace a C or C++ definition
27with a Rust definition, use [blocklisting](./blocklisting.md).
28