Skip to content

Commit

Permalink
Update getrandom to 0.2 (#1041)
Browse files Browse the repository at this point in the history
* 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 <joerichey@google.com>
Co-authored-by: Vinzent Steinberg <Vinzent.Steinberg@gmail.com>
  • Loading branch information
josephlr and vks committed Sep 15, 2020
1 parent 7a1f51c commit 85c32ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -16,6 +16,7 @@ You may also find the [Upgrade Guide](https://rust-random.github.io/book/update.
- Implement weighted sampling without replacement (#976, #1013)

### Changes
- `getrandom` updated to v0.2 (#1041)
- `ThreadRng` is no longer `Copy` to enable safe usage within thread-local destructors (see #968)
- `gen_range(a, b)` was replaced with `gen_range(a..b)`, and `gen_range(a..=b)`
is supported (#744, #1003). Note that `a` and `b` can no longer be references or SIMD types.
Expand Down
2 changes: 1 addition & 1 deletion rand_core/Cargo.toml
Expand Up @@ -25,7 +25,7 @@ serde1 = ["serde"] # enables serde for BlockRng wrapper

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
getrandom = { version = "0.1", optional = true }
getrandom = { version = "0.2", optional = true }

[package.metadata.docs.rs]
# To build locally:
Expand Down
15 changes: 15 additions & 0 deletions rand_core/src/error.rs
Expand Up @@ -28,10 +28,14 @@ pub struct Error {
impl Error {
/// Codes at or above this point can be used by users to define their own
/// custom errors.
///
/// This is identical to [`getrandom::Error::CUSTOM_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.CUSTOM_START).
pub const CUSTOM_START: u32 = (1 << 31) + (1 << 30);
/// Codes below this point represent OS Errors (i.e. positive i32 values).
/// Codes at or above this point, but below [`Error::CUSTOM_START`] are
/// reserved for use by the `rand` and `getrandom` crates.
///
/// This is identical to [`getrandom::Error::INTERNAL_START`](https://docs.rs/getrandom/latest/getrandom/struct.Error.html#associatedconstant.INTERNAL_START).
pub const INTERNAL_START: u32 = 1 << 31;

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

#[cfg(feature = "std")]
impl std::error::Error for ErrorCode {}

#[cfg(test)]
mod test {
#[cfg(feature = "getrandom")]
#[test]
fn test_error_codes() {
// Make sure the values are the same as in `getrandom`.
assert_eq!(super::Error::CUSTOM_START, getrandom::Error::CUSTOM_START);
assert_eq!(super::Error::INTERNAL_START, getrandom::Error::INTERNAL_START);
}
}

0 comments on commit 85c32ff

Please sign in to comment.