1# Preventing the Derivation of `Default` 2 3`bindgen` will attempt to derive/impl the `Default` traits on a best-effort basis. 4Sometimes, we need customize the implement of `Default` for certain types, 5In these cases, the `nodefault` annotation can be used to prevent bindgen 6to autoderive the `Default` traits for a type. 7 8### Library 9 10* [`bindgen::Builder::no_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_default) 11 12### Command Line 13 14* `--no-default <regex>` 15 16### Annotations 17 18```c 19/** 20 * We need to specify some preset values as the Default of Header. 21 * 22 * for example: 23 * 24 * <div rustbindgen nodefault></div> 25 */ 26struct Header { 27 unsigned int magic; 28 unsigned char data[252]; 29}; 30 31... 32``` 33 34### Customize Implements 35 36```rust,ignore 37// Include the generated bindings. 38include!(concat!(env!("OUT_DIR"), "/bindings.rs")); 39 40impl Default for Header { 41 fn default() -> Self { 42 Self { 43 magic: 0x10203040u32, 44 data: [0; 252usize], 45 } 46 } 47} 48``` 49