Skip to content

Commit e9f99fb

Browse files
authored
docs: Add README and expand crate-level docs
Signed-off-by: John Nunley <[email protected]>
1 parent 15b4b81 commit e9f99fb

File tree

2 files changed

+106
-2
lines changed

2 files changed

+106
-2
lines changed

README.md

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,68 @@
1-
# fastrand-contrib
1+
# fastrand
22

3-
TODO
3+
[![Build](https://github.com/smol-rs/fastrand/workflows/Build%20and%20test/badge.svg)](
4+
https://github.com/smol-rs/fastrand/actions)
5+
[![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)](
6+
https://github.com/smol-rs/fastrand)
7+
[![Cargo](https://img.shields.io/crates/v/fastrand.svg)](
8+
https://crates.io/crates/fastrand)
9+
[![Documentation](https://docs.rs/fastrand/badge.svg)](
10+
https://docs.rs/fastrand)
411

12+
Extension functionality for the [`fastrand`] crate.
513

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.

src/lib.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,47 @@
11
//! Extension functionality for the [`fastrand`] crate.
22
//!
3+
//! This crate contains code that may be of some use to users of [`fastrand`]. Code contained in
4+
//! this crate is not included in [`fastrand`] due to either the niche not being large enough to
5+
//! justify the new functionality or for semver concerns.
6+
//!
7+
//! ## Usage
8+
//!
9+
//! Various functions are exposed in this crate as top-level functions. These manipulate the global
10+
//! thread-local RNG and can be used without any local state. Note that these require the `"std"`
11+
//! default feature to be enabled.
12+
//!
13+
//! ```
14+
//! # #[cfg(feature = "std")] {
15+
//! use fastrand_contrib::f32_range;
16+
//!
17+
//! let x = f32_range(1.5..3.0);
18+
//! assert!(x >= 1.5 && x < 3.0);
19+
//! # }
20+
//! ```
21+
//!
22+
//! To extend [`fastrand::Rng`], import the [`RngExt`] trait.
23+
//!
24+
//! ```
25+
//! use fastrand_contrib::RngExt;
26+
//! ```
27+
//!
28+
//! Now, all new methods are available on [`fastrand::Rng`].
29+
//!
30+
//! ```
31+
//! use fastrand::Rng;
32+
//! use fastrand_contrib::RngExt;
33+
//!
34+
//! let mut rng = Rng::with_seed(0x1234);
35+
//! let x = rng.f32_range(1.5..3.0);
36+
//! assert!(x >= 1.5 && x < 3.0);
37+
//! ```
38+
//! # Features
39+
//!
40+
//! - `std` (enabled by default): Enables the `std` library. Freestanding functions only work with this
41+
//! feature enabled. Also enables the `fastrand/std` feature.
42+
//!
343
//! [`fastrand`]: https://crates.io/crates/fastrand
44+
//! [`fastrand::Rng`]: https://docs.rs/fastrand/latest/fastrand/struct.Rng.html
445
546
#![cfg_attr(not(feature = "std"), no_std)]
647

0 commit comments

Comments
 (0)