|
1 |
| -# Bitflags |
| 1 | +# Conventions |
| 2 | + |
| 3 | +In order to achieve our goal of wrapping [libc][libc] code in idiomatic rust |
| 4 | +constructs with minimal performance overhead, we follow the following |
| 5 | +conventions. |
| 6 | + |
| 7 | +Note that, thus far, not all the code follows these conventions and not all |
| 8 | +conventions we try to follow have been documented here. If you find an instance |
| 9 | +of either, feel free to remedy the flaw by opening a pull request with |
| 10 | +appropriate changes or additions. |
| 11 | + |
| 12 | + |
| 13 | +## Integer Constants |
| 14 | + |
| 15 | +We do not define integer constants ourselves, but use or reexport them from the |
| 16 | +[libc crate][libc]. |
| 17 | + |
| 18 | + |
| 19 | +## Bitflags |
2 | 20 |
|
3 | 21 | We represent sets of constants that are intended to be combined using bitwise
|
4 | 22 | operations as parameters to functions by types defined using the `bitflags!`
|
5 |
| -macro from the [bitflags crate](https://crates.io/crates/bitflags/). |
6 |
| -Instead of providing the concrete values ourselves, we prefer taking the |
7 |
| -constants defined in [libc crate](https://crates.io/crates/libc/). |
| 23 | +macro from the [bitflags crate][bitflags]. |
| 24 | + |
| 25 | + |
| 26 | +## Enumerations |
| 27 | + |
| 28 | +We represent sets of constants that are intended as mutually exclusive arguments |
| 29 | +to parameters of functions by [enumerations][enum]. |
| 30 | + |
| 31 | + |
| 32 | +## Structures Initialized by libc Functions |
| 33 | + |
| 34 | +Whenever we need to use a [libc][libc] function to properly initialize a |
| 35 | +variable and said function allows us to use uninitialized memory, we use |
| 36 | +[`std::mem::uninitialized`][std_uninitialized] (or [`core::mem::uninitialized`][core_uninitialized]) |
| 37 | +when defining the variable. This allows us to avoid the overhead incurred by |
| 38 | +zeroing or otherwise initializing the variable. |
| 39 | + |
| 40 | +[bitflags]: https://crates.io/crates/bitflags/ |
| 41 | +[core_uninitialized]: https://doc.rust-lang.org/core/mem/fn.uninitialized.html |
| 42 | +[enum]: https://doc.rust-lang.org/reference.html#enumerations |
| 43 | +[libc]: https://crates.io/crates/libc/ |
| 44 | +[std_uninitialized]: https://doc.rust-lang.org/std/mem/fn.uninitialized.html |
0 commit comments