Skip to content

Commit 2c5840f

Browse files
KarelPeetersemilio
authored andcommitted
Add must-use-type to the book.
1 parent 01a7a4d commit 2c5840f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md)
2020
- [Preventing the Derivation of `Debug`](./nodebug.md)
2121
- [Preventing the Derivation of `Default`](./nodefault.md)
22+
- [Annotating types with `#[must-use]`](./must-use-types.md)
2223
- [Generating Bindings to C++](./cpp.md)
2324
- [Generating Bindings to Objective-c](./objc.md)
2425
- [Using Unions](./using-unions.md)

book/src/must-use-types.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Annotating types with `#[must-use]`
2+
3+
`bindgen` can be instructed to annotate certain types with
4+
[`#[must_use]`](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute).
5+
6+
Some libraries have a common error type, returned by lots of their functions,
7+
which needs to be checked after every call. In these cases it's useful to add `#[must_use]` to this type, so the Rust
8+
compiler emits a warning when the check is missing.
9+
### Library
10+
11+
* [`bindgen::Builder::must_use_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.must_use_type)
12+
13+
### Command Line
14+
15+
* `--must-use-type <regex>`
16+
17+
### Annotations
18+
19+
```c
20+
/** <div rustbindgen mustusetype></div> */
21+
struct ErrorType {
22+
// ...
23+
};
24+
25+
...
26+
```
27+

0 commit comments

Comments
 (0)