Preventing the Derivation of Copy and Clone - 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

# Preventing the Derivation of `Copy` and `Clone`

`bindgen` will attempt to derive the `Copy` and `Clone` traits on a best-effort basis. Sometimes, it might not understand that although adding `#[derive(Copy, Clone)]` to a translated type definition will compile, it still shouldn’t do that for reasons it can’t know. In these cases, the `nocopy` annotation can be used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type.

### Library

- `bindgen::Builder::no_copy`

### Command Line

- `--no-copy <regex>`

### Annotations

    /**
     * Although bindgen can't know, this struct is not safe to move because pthread
     * mutexes can't move in memory!
     *
     * <div rustbindgen nocopy></div>
     */
    struct MyMutexWrapper {
        pthread_mutex_t raw;
        // ...
    };