diff options
author | Karel Peeters <karel.peeters.leuven@gmail.com> | 2021-07-23 18:46:31 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2021-07-31 13:47:39 +0200 |
commit | 2c5840fb3d6400922e8f136f44fe787b6dd7ed7a (patch) | |
tree | ba2d88548202023cf8cb9aff218cbf1012f3de63 | |
parent | 01a7a4d7158c2d227dc55199fe1a4306dcbe68cf (diff) |
Add must-use-type to the book.
-rw-r--r-- | book/src/SUMMARY.md | 1 | ||||
-rw-r--r-- | book/src/must-use-types.md | 27 |
2 files changed, 28 insertions, 0 deletions
diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 65ed0870..f9cc869f 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -19,6 +19,7 @@ - [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md) - [Preventing the Derivation of `Debug`](./nodebug.md) - [Preventing the Derivation of `Default`](./nodefault.md) + - [Annotating types with `#[must-use]`](./must-use-types.md) - [Generating Bindings to C++](./cpp.md) - [Generating Bindings to Objective-c](./objc.md) - [Using Unions](./using-unions.md) diff --git a/book/src/must-use-types.md b/book/src/must-use-types.md new file mode 100644 index 00000000..490339c9 --- /dev/null +++ b/book/src/must-use-types.md @@ -0,0 +1,27 @@ +# Annotating types with `#[must-use]` + +`bindgen` can be instructed to annotate certain types with +[`#[must_use]`](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute). + +Some libraries have a common error type, returned by lots of their functions, +which needs to be checked after every call. In these cases it's useful to add `#[must_use]` to this type, so the Rust +compiler emits a warning when the check is missing. +### Library + +* [`bindgen::Builder::must_use_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.must_use_type) + +### Command Line + +* `--must-use-type <regex>` + +### Annotations + +```c +/** <div rustbindgen mustusetype></div> */ +struct ErrorType { + // ... +}; + +... +``` + |