Skip to content

Commit 85c32ff

Browse files
josephlrvks
andauthored
Update getrandom to 0.2 (#1041)
* Update getrandom to 0.2 * Make sure that the error codes are identical to `getrandom` * rand_core: Add links to Error cross-refs Signed-off-by: Joe Richey <[email protected]> Co-authored-by: Vinzent Steinberg <[email protected]>
1 parent 7a1f51c commit 85c32ff

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
1616
- Implement weighted sampling without replacement (#976, #1013)
1717

1818
### Changes
19+
- `getrandom` updated to v0.2 (#1041)
1920
- `ThreadRng` is no longer `Copy` to enable safe usage within thread-local destructors (see #968)
2021
- `gen_range(a, b)` was replaced with `gen_range(a..b)`, and `gen_range(a..=b)`
2122
is supported (#744, #1003). Note that `a` and `b` can no longer be references or SIMD types.

rand_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ serde1 = ["serde"] # enables serde for BlockRng wrapper
2525

2626
[dependencies]
2727
serde = { version = "1", features = ["derive"], optional = true }
28-
getrandom = { version = "0.1", optional = true }
28+
getrandom = { version = "0.2", optional = true }
2929

3030
[package.metadata.docs.rs]
3131
# To build locally:

rand_core/src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ pub struct Error {
2828
impl Error {
2929
/// Codes at or above this point can be used by users to define their own
3030
/// custom errors.
31+
///
32+
/// This is identical to [`getrandom::Error::CUSTOM_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.CUSTOM_START).
3133
pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30);
3234
/// Codes below this point represent OS Errors (i.e. positive i32 values).
3335
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
3436
/// reserved for use by the `rand` and `getrandom` crates.
37+
///
38+
/// This is identical to [`getrandom::Error::INTERNAL_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.INTERNAL_START).
3539
pub const INTERNAL_START: u32 = 1 << 31;
3640

3741
/// Construct from any type supporting `std::error::Error`
@@ -208,3 +212,14 @@ impl fmt::Display for ErrorCode {
208212

209213
#[cfg(feature = "std")]
210214
impl std::error::Error for ErrorCode {}
215+
216+
#[cfg(test)]
217+
mod test {
218+
#[cfg(feature = "getrandom")]
219+
#[test]
220+
fn test_error_codes() {
221+
// Make sure the values are the same as in `getrandom`.
222+
assert_eq!(super::Error::CUSTOM_START, getrandom::Error::CUSTOM_START);
223+
assert_eq!(super::Error::INTERNAL_START, getrandom::Error::INTERNAL_START);
224+
}
225+
}

0 commit comments

Comments
 (0)