File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 19
19
- [ Preventing the Derivation of ` Copy ` and ` Clone ` ] ( ./nocopy.md )
20
20
- [ Preventing the Derivation of ` Debug ` ] ( ./nodebug.md )
21
21
- [ Preventing the Derivation of ` Default ` ] ( ./nodefault.md )
22
+ - [ Annotating types with ` #[must-use] ` ] ( ./must-use-types.md )
22
23
- [ Generating Bindings to C++] ( ./cpp.md )
23
24
- [ Generating Bindings to Objective-c] ( ./objc.md )
24
25
- [ Using Unions] ( ./using-unions.md )
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments