Back to Rust Bindgen

Annotating Types with `#[must-use]`

book/src/must-use-types.md

0.72.1740 B
Original Source

Annotating Types with #[must-use]

bindgen can be instructed to annotate certain types with #[must_use].

Some libraries have a common error type, returned by many 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

Command Line

  • --must-use-type <regex>

Annotations

c
/** <div rustbindgen mustusetype></div> */
struct ErrorType {
    // ...
};

...