|
| 1 | +# Contributing to Rand |
| 2 | + |
| 3 | +Thank you for your interest in contributing to Rand! |
| 4 | + |
| 5 | +The following is a list of notes and tips for when you want to contribute to |
| 6 | +Rand with a pull request. |
| 7 | + |
| 8 | +If you want to make major changes, it is usually best to open an issue to |
| 9 | +discuss the idea first. |
| 10 | + |
| 11 | +Rand doesn't (yet) use rustfmt. It is best to follow the style of the |
| 12 | +surrounding code, and try to keep an 80 character line limit. |
| 13 | + |
| 14 | + |
| 15 | +## Documentation |
| 16 | + |
| 17 | +We especially welcome documentation PRs. |
| 18 | + |
| 19 | +As of Rust 1.25 there are differences in how stable and nightly render |
| 20 | +documentation links. Make sure it works on stable, then nightly should be good |
| 21 | +too. One Travis CI build checks for dead links using `cargo-deadlinks`. If you |
| 22 | +want to run the check locally: |
| 23 | +```sh |
| 24 | +cargo install cargo-deadlinks |
| 25 | +# It is recommended to remove left-over files from previous compilations |
| 26 | +rm -rf /target/doc |
| 27 | +cargo doc --no-deps |
| 28 | +cargo deadlinks --dir target/doc |
| 29 | +``` |
| 30 | + |
| 31 | +When making changes to code examples in the documentation, make sure they build |
| 32 | +with: |
| 33 | +```sh |
| 34 | +cargo test --doc |
| 35 | +``` |
| 36 | + |
| 37 | +A helpful command to rebuild documentation automatically on save (only works on |
| 38 | +Linux): |
| 39 | +``` |
| 40 | +while inotifywait -r -e close_write src/ rand_core/; do cargo doc; done |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | +## Testing |
| 45 | + |
| 46 | +Rand already contains a number of unit tests, but could use more. Also the |
| 47 | +existing ones could use clean-up. Any work on the tests is appreciated. |
| 48 | + |
| 49 | +Not every change or new bit of functionality requires tests, but if you can |
| 50 | +think of a test that adds value, please add it. |
| 51 | + |
| 52 | +Depending on the code you change, test with one of: |
| 53 | +```sh |
| 54 | +cargo test |
| 55 | +cargo test --package rand_core |
| 56 | +# Test log, serde and 128-bit support |
| 57 | +cargo test --features serde1,log,nightly |
| 58 | +``` |
| 59 | + |
| 60 | +We want to be able to not only run the unit tests with `std` available, but also |
| 61 | +without. Because `thread_rng()` and `FromEntropy` are not available without the |
| 62 | +`std` feature, you may have to disable a new test with `#[cfg(feature="std")]`. |
| 63 | +In other cases using `::test::rng` with a constant seed is a good option: |
| 64 | +```rust |
| 65 | +let mut rng = ::test::rng(528); // just pick some number |
| 66 | +``` |
| 67 | + |
| 68 | +Only the unit tests should work in `no_std` mode, we don't want to complicate |
| 69 | +the doc-tests. Run the tests with: |
| 70 | +```sh |
| 71 | +# Test no_std support |
| 72 | +cargo test --lib --no-default-features |
| 73 | +cargo test --package rand_core --no-default-features |
| 74 | + |
| 75 | +# Test no_std+alloc support; requires nightly |
| 76 | +cargo test --lib --no-default-features --features alloc |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | +## Benchmarking |
| 81 | + |
| 82 | +A lot of code in Rand is performance-sensitive, most of it is expected to be |
| 83 | +used in hot loops in some libraries/applications. If you change code in the |
| 84 | +`rngs`, `prngs` or `distributions` modules, especially when you see an 'obvious |
| 85 | +cleanup', make sure the benchmarks do not regress. It is nice to report the |
| 86 | +benchmark results in the PR (or to report nothing's changed). |
| 87 | + |
| 88 | +```sh |
| 89 | +# Benchmarks (requires nightly) |
| 90 | +cargo bench |
| 91 | +# Some benchmarks have a faster path with i128_support |
| 92 | +cargo bench --features=nightly |
| 93 | +``` |
0 commit comments