Skip to content

Commit 4be63a7

Browse files
miikkasemilio
authored andcommitted
Small fixes and clarifications to user guide
Some letter casing, typing, formatting, and grammar errors are fixed. Links added to docs.rs in some text referring to documentation there, as well as to other external resources. For inclusivity, the tutorial's sanity test is renamed to a smoke test.
1 parent 0b6f8f6 commit 4be63a7

File tree

10 files changed

+57
-44
lines changed

10 files changed

+57
-44
lines changed

book/src/SUMMARY.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
- [Create a `wrapper.h` Header](./tutorial-2.md)
99
- [Create a `build.rs` File](./tutorial-3.md)
1010
- [Include the Generated Bindings in `src/lib.rs`](./tutorial-4.md)
11-
- [Write a Sanity Test](./tutorial-5.md)
11+
- [Write a Smoke Test](./tutorial-5.md)
1212
- [Publish Your Crate!](./tutorial-6.md)
13-
- [Bindings for non-system libraries](./non-system-libraries.md)
13+
- [Bindings for Non-System Libraries](./non-system-libraries.md)
1414
- [Command Line Usage](./command-line-usage.md)
1515
- [Customizing the Generated Bindings](./customizing-generated-bindings.md)
1616
- [Allowlisting](./allowlisting.md)
@@ -20,11 +20,11 @@
2020
- [Preventing the Derivation of `Copy` and `Clone`](./nocopy.md)
2121
- [Preventing the Derivation of `Debug`](./nodebug.md)
2222
- [Preventing the Derivation of `Default`](./nodefault.md)
23-
- [Annotating types with `#[must-use]`](./must-use-types.md)
24-
- [Field visibility](./visibility.md)
25-
- [Code formatting](./code-formatting.md)
23+
- [Annotating Types with `#[must-use]`](./must-use-types.md)
24+
- [Field Visibility](./visibility.md)
25+
- [Code Formatting](./code-formatting.md)
2626
- [Generating Bindings to C++](./cpp.md)
27-
- [Generating Bindings to Objective-c](./objc.md)
27+
- [Generating Bindings to Objective-C](./objc.md)
2828
- [Using Unions](./using-unions.md)
2929
- [Using Bitfields](./using-bitfields.md)
3030
- [Using Flexible Array Members](./using-fam.md)

book/src/command-line-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ directory to your `$PATH` to use `bindgen`.
1313
output file path for the generated bindings. If the output file path is not
1414
supplied, the bindings are printed to `stdout`.
1515

16-
If we wanted to generated Rust FFI bindings from a C header named `input.h` and
16+
If we wanted to generate Rust FFI bindings from a C header named `input.h` and
1717
put them in the `bindings.rs` file, we would invoke `bindgen` like this:
1818

1919
```bash

book/src/faq.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ creates linking errors.
4747
However, if you are compiling the C/C++ yourself (rather than using a system
4848
shared library, for example), then you can pass `-fkeep-inline-functions` or
4949
`-fno-inline-functions` to `gcc` or `clang`, and invoke `bindgen` with either
50-
the `bindgen::Builder::generate_inline_functions` method or the
51-
`--generate-inline-functions` flag.
50+
the [`bindgen::Builder::generate_inline_functions`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.generate_inline_functions)
51+
method or the `--generate-inline-functions` flag.
5252
5353
Note that these functions and methods are usually marked inline for a reason:
5454
they tend to be hot. The above workaround makes them an out-of-line call, which
5555
might not provide acceptable performance.
5656
5757
As an alternative, you can invoke `bindgen` with either the
58-
`bindgen::Builder::wrap_static_fns` method or the `--wrap-static-fns` flag.
59-
Which generates a C source file that can be compiled against the input headers
60-
to produce Rust headers for `static` and `static inline` functions. See [How to
61-
handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405)
58+
[`bindgen::Builder::wrap_static_fns`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.wrap_static_fns)
59+
method or the `--wrap-static-fns` flag. That generates a C source file that can
60+
be compiled against the input headers to produce Rust bindings for `static` and
61+
`static inline` functions. See [How to handle `static inline` functions](https://github.com/rust-lang/rust-bindgen/discussions/2405)
6262
for further information.
6363
6464
### Does `bindgen` support the C++ Standard Template Library (STL)?
@@ -81,8 +81,8 @@ possible that bindgen will generate padding fields named `__bindgen_padding_N`.
8181
As these fields might be present when compiling for one architecture but not
8282
for an other, you should not initialize these fields manually when initializing
8383
the struct. Instead, use the `Default` trait. You can either enable this when
84-
constructing the `Builder` using the `derive_default` method, or you can
85-
implement this per struct using:
84+
constructing the `Builder` using the [`derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default)
85+
method, or you can implement this per struct using:
8686
8787
```rust,ignore
8888
impl Default for SRC_DATA {
@@ -107,7 +107,7 @@ be automatically initialized by `..Default::default()`.
107107

108108
### How to generate bindings for a custom target?
109109

110-
To generate bindings for a custom target you only need to pass the `--target`
110+
To generate bindings for a custom target you only need to pass the [`--target`](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-target)
111111
argument to `libclang`. For example, if you want to generate bindings for the
112112
`armv7a-none-eabi` target using the command line, you need to invoke `bindgen`
113113
like so:

book/src/must-use-types.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
# Annotating types with `#[must-use]`
1+
# Annotating Types with `#[must-use]`
22

33
`bindgen` can be instructed to annotate certain types with
44
[`#[must_use]`](https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute).
55

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.
6+
Some libraries have a common error type, returned by many of their functions,
7+
which needs to be checked after every call. In these cases it's useful to add
8+
`#[must_use]` to this type, so the Rust compiler emits a warning when the check
9+
is missing.
10+
911
### Library
1012

1113
* [`bindgen::Builder::must_use_type`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.must_use_type)

book/src/nocopy.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
basis. Sometimes, it might not understand that although adding `#[derive(Copy,
55
Clone)]` to a translated type definition will compile, it still shouldn't do
66
that for reasons it can't know. In these cases, the `nocopy` annotation can be
7-
used to prevent bindgen to autoderive the `Copy` and `Clone` traits for a type.
7+
used to prevent bindgen from automatically deriving the `Copy` and `Clone`
8+
traits for a type.
89

910
### Library
1011

12+
* [`bindgen::Builder::derive_copy`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_copy)
1113
* [`bindgen::Builder::no_copy`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_copy)
1214

1315
### Command Line
1416

17+
* `--no-derive-copy`
1518
* `--no-copy <regex>`
1619

1720
### Annotations

book/src/nodebug.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
`bindgen` will attempt to derive the `Debug` traits on a best-effort
44
basis. Sometimes, it might not understand that although adding `#[derive(Debug)]` to a translated type definition will compile, it still shouldn't do
55
that for reasons it can't know. In these cases, the `nodebug` annotation can be
6-
used to prevent bindgen to autoderive the `Debug` traits for a type.
6+
used to prevent bindgen from automatically deriving the `Debug` trait for a type.
77

88
### Library
99

10+
* [`bindgen::Builder::derive_debug`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_debug)
1011
* [`bindgen::Builder::no_debug`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_debug)
1112

1213
### Command Line
1314

15+
* `--no-derive-debug`
1416
* `--no-debug <regex>`
1517

1618
### Annotations

book/src/nodefault.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
# Preventing the Derivation of `Default`
22

3+
By default, `Default` is not derived.
4+
35
`bindgen` will attempt to derive/impl the `Default` traits on a best-effort basis.
4-
Sometimes, we need customize the implement of `Default` for certain types,
5-
In these cases, the `nodefault` annotation can be used to prevent bindgen
6-
to autoderive the `Default` traits for a type.
6+
Sometimes, we need customize the implementation of `Default` for certain types.
7+
In these cases, the `nodefault` annotation can be used to prevent bindgen from
8+
automatically deriving the `Default` trait for a type.
79

810
### Library
911

12+
* [`bindgen::Builder::derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default)
1013
* [`bindgen::Builder::no_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.no_default)
1114

1215
### Command Line
1316

17+
* `--with-derive-default`
1418
* `--no-default <regex>`
1519

1620
### Annotations

book/src/objc.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
# Generating Bindings to Objective-C
22

3-
`bindgen` does not (yet) have full objective-c support but it can generate bindings
4-
for a lot of the apple frameworks without too much blocklisting.
3+
`bindgen` does not (yet) have full Objective-C support, but it can generate
4+
bindings for many of the Apple frameworks without too much blocklisting.
55

6-
In order to generate bindings, you will need `-x objective-c` as the clang
7-
args. If you'd like to use [block](https://crates.io/crates/block) you will need
6+
In order to generate bindings, you will need `-x objective-c` as a clang arg. If
7+
you'd like to use [block](https://crates.io/crates/block) you will need
88
`-fblocks` as a clang arg as well.
99

1010
Depending on your setup, you may need `--generate-block` to generate the block
1111
function aliases and `--block-extern-crate` to insert a `extern crate block` at
1212
the beginning of the generated bindings. The same logic applies to the
1313
`--objc-extern-crate` parameter.
1414

15-
The objective-c classes will be represented as a `struct Foo(id)` and a trait
16-
`IFoo` where `Foo` is the objective-c class and `id` is an alias for `*mut
17-
objc::runtime::Object` (the pointer to the objective-c instance). The trait
15+
The Objective-C classes will be represented as a `struct Foo(id)` and a trait
16+
`IFoo` where `Foo` is the Objective-C class and `id` is an alias for `*mut
17+
objc::runtime::Object` (the pointer to the Objective-C instance). The trait
1818
`IFoo` is needed to allow for the generated inheritance.
1919

20-
Functions that use or return objective-c pointers of instance `Foo` will return
20+
Functions that use or return Objective-C pointers of instance `Foo` will return
2121
`Foo`. The reason this works is because `Foo` represented as `transparent`.
22-
This will be helpful for a lot of objective-c frameworks however there are some
22+
This will be helpful for many Objective-C frameworks. However, there are some
2323
cases where functions return `instancetype` which is a type alias for `id` so
2424
an occasional `foo.0` may be required. An example of this would in the UIKit
2525
framework should you want to add a `UILabel` to a
@@ -42,7 +42,7 @@ stands for interface.
4242
* Protocols which match to rust traits with prefixes of `P` which
4343
stands for Protocol.
4444
* Classes will generate `struct Foo(id)` where `Foo` is the class
45-
name and `id` is a pointer to the objective-c Object.
45+
name and `id` is a pointer to the Objective-C Object.
4646
* Blocks
4747

4848
## Useful Notes
@@ -52,16 +52,16 @@ name and `id` is a pointer to the objective-c Object.
5252
[here](https://github.com/rust-lang/rust-bindgen/issues/1211#issuecomment-569804287).
5353
* The generated bindings will almost certainly have some conflicts so you will
5454
have to blocklist a few things. There are a few cases of the parameters being
55-
poorly named in the objective-c headers. But if you're using anything with
55+
poorly named in the Objective-C headers. But if you're using anything with
5656
Core Foundation, you'll find that `time.h` as has a variable called timezone that
5757
conflicts with some of the things in `NSCalendar.h`.
58-
* Some small subset of the function headers in the apple frameworks go against
59-
apple's guidelines for parameter names and duplicate the names in the header
58+
* Some small subset of the function headers in the Apple frameworks go against
59+
Apple's guidelines for parameter names and duplicate the names in the header
6060
which won't compile as mentioned
6161
[here](https://github.com/rust-lang/rust-bindgen/issues/1705).
6262
* instancetype return methods does not return `Self` for you given class, it
6363
returns a `mut * objc::runtime::Objc` which is aliased as `id`. This is because
64-
objective-c's inheritance doesn't perfectly match that of rusts.
64+
Objective-C's inheritance doesn't perfectly match that of Rust's.
6565
* Depending on what you're trying `bindgen` against, you may end up including
6666
all of Core Foundation and any other frameworks. This will result in a very
6767
long compile time.

book/src/tutorial-5.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Write a Sanity Test
1+
# Write a Smoke Test
22

3-
Finally, to tie everything together, let's write a sanity test that round trips
3+
Finally, to tie everything together, let's write a smoke test that round trips
44
some text through compression and decompression, and then asserts that it came
55
back out the same as it went in. This is a little wordy using the raw FFI
66
bindings, but hopefully we wouldn't usually ask people to do this, we'd provide
77
a nice Rust-y API on top of the raw FFI bindings for them. However, since this
8-
is for testing the bindings directly, our sanity test will use the bindings
8+
is for testing the bindings directly, our smoke test will use the bindings
99
directly.
1010

1111
The test data I'm round tripping are some Futurama quotes I got off the internet

book/src/using-bitfields.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pre-existing definition for the bitfield unit type.
1515

1616
## Bitfield examples
1717

18-
For this discussion, we will use the following C type definitions and functions.
18+
For this discussion, we will use the following C type definitions and functions:
1919
```c
2020
typedef struct {
2121
unsigned int a: 1;
@@ -76,7 +76,9 @@ StructWithBitfields: a:1, b:1, c:0
7676

7777
To create a new bitfield in Rust, use the bitfield allocation unit constructor.
7878

79-
Note: This requires the Builder's derive_default to be set to true, otherwise the necessary Default functions won't be generated.
79+
Note: This requires the `Builder`'s [`derive_default`](https://docs.rs/bindgen/latest/bindgen/struct.Builder.html#method.derive_default)
80+
to be set to `true`. Otherwise the necessary `Default` functions won't be
81+
generated.
8082

8183
```rust,ignore
8284
let bfield = StructWithBitfields{

0 commit comments

Comments
 (0)