|
1 | | -# fastrand-contrib |
| 1 | +# fastrand |
2 | 2 |
|
3 | | -TODO |
| 3 | +[]( |
| 4 | +https://github.com/smol-rs/fastrand/actions) |
| 5 | +[]( |
| 6 | +https://github.com/smol-rs/fastrand) |
| 7 | +[]( |
| 8 | +https://crates.io/crates/fastrand) |
| 9 | +[]( |
| 10 | +https://docs.rs/fastrand) |
4 | 11 |
|
| 12 | +Extension functionality for the [`fastrand`] crate. |
5 | 13 |
|
| 14 | +This crate contains code that may be of some use to users of [`fastrand`]. Code contained in |
| 15 | +this crate is not included in [`fastrand`] due to either the niche not being large enough to |
| 16 | +justify the new functionality or for semver concerns. |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +Various functions are exposed in this crate as top-level functions. These manipulate the global |
| 21 | +thread-local RNG and can be used without any local state. Note that these require the `"std"` |
| 22 | +default feature to be enabled. |
| 23 | + |
| 24 | +``` |
| 25 | +use fastrand_contrib::f32_range; |
| 26 | +
|
| 27 | +let x = f32_range(1.5..3.0); |
| 28 | +assert!(x >= 1.5 && x < 3.0); |
| 29 | +``` |
| 30 | + |
| 31 | +To extend [`fastrand::Rng`], import the [`RngExt`] trait. |
| 32 | + |
| 33 | +``` |
| 34 | +use fastrand_contrib::RngExt; |
| 35 | +``` |
| 36 | + |
| 37 | +Now, all new methods are available on [`fastrand::Rng`]. |
| 38 | + |
| 39 | +``` |
| 40 | +use fastrand::Rng; |
| 41 | +use fastrand_contrib::RngExt; |
| 42 | +
|
| 43 | +let mut rng = Rng::with_seed(0x1234); |
| 44 | +let x = rng.f32_range(1.5..3.0); |
| 45 | +assert!(x >= 1.5 && x < 3.0); |
| 46 | +``` |
| 47 | + |
| 48 | +[`fastrand`]: https://crates.io/crates/fastrand |
| 49 | +[`fastrand::Rng`]: https://docs.rs/fastrand/latest/fastrand/struct.Rng.html |
| 50 | + |
| 51 | +# Features |
| 52 | + |
| 53 | +- `std` (enabled by default): Enables the `std` library. Freestanding functions only work with this feature enabled. Also enables the `fastrand/std` feature. |
| 54 | + |
| 55 | +## License |
| 56 | + |
| 57 | +Licensed under either of |
| 58 | + |
| 59 | + * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 60 | + * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 61 | + |
| 62 | +at your option. |
| 63 | + |
| 64 | +#### Contribution |
| 65 | + |
| 66 | +Unless you explicitly state otherwise, any contribution intentionally submitted |
| 67 | +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be |
| 68 | +dual licensed as above, without any additional terms or conditions. |
0 commit comments