Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update getrandom to 0.2 #1041

Merged
merged 4 commits into from Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
josephlr marked this conversation as resolved.
Show resolved Hide resolved
- `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);
}
}