Skip to content

Update rand_core::Error in line with getrandom::Error - #864

Merged
dhardy merged 4 commits into
rust-random:masterfrom
dhardy:error
Aug 28, 2019
Merged

Update rand_core::Error in line with getrandom::Error#864
dhardy merged 4 commits into
rust-random:masterfrom
dhardy:error

Conversation

@dhardy

Copy link
Copy Markdown
Member

This mirrors the changes in rust-random/getrandom#54 . All changes to rand_core are additive (not breaking).

rand_jitter gets updated to put its error codes within the appropriate range, and also a minor "fix": use of repr(u32) on the enum (which I don't believe is a breaking change, since either way for e: TimerError, e as u32 and e as isize are supported, while u32::from(e) is not).

Open question: should we copy rand_jitter error descriptions into rand_core when cfg(all(feature="getrandom", not(feature="std")))? I'm leaning against doing this, since it increases crate size while benefiting very few people.

Also see #837.

@vks

vks commented Aug 9, 2019

Copy link
Copy Markdown
Contributor

So changing the error codes is not considered a breaking change for rand_jitter?

I'm fine with not copying the error descriptions, since I consider rand_jitter to be kind of deprecated.

#[cfg(all(feature="getrandom", not(feature="std")))] {
getrandom::Error::from(self.code).fmt(f)
}
#[cfg(not(feature="getrandom"))] {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use cfg(not(any(feature="getrandom", feature="std"))). Same for Display impl. Maybe use cfg_if to be less error-prone?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std implies getrandom

Comment threadrand_core/src/error.rs Outdated
impl From<Error> for std::io::Error {
#[inline]
fn from(error: Error) -> Self {
std::io::Error::new(std::io::ErrorKind::Other, error)

@newpavlovnewpavlovAug 9, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe write something like this instead?

ifletSome(code) = error.raw_os_error(){
std::io::Error::from_raw_os_error(code)}else{
std::io::Error::new(std::io::ErrorKind::Other, error)}

use core::fmt;

/// Base code for all `JitterRng` errors
const ERROR_BASE: u32 = 0xAE53_0400;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe write it like const ERROR_BASE: u32 = Error::INTERNAL_START + <some const>?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually clearer? To me it's not.

@newpavlovnewpavlov mentioned this pull request Aug 16, 2019
@dhardy

Copy link
Copy Markdown
MemberAuthor

@newpavlov I added your suggestion; sorry about the delay. I think the other points you mentioned can be left?

@newpavlov

Copy link
Copy Markdown
Member

@dhardy Yes, they were just suggestions, so you can merge this PR as-is.

@dhardy

Copy link
Copy Markdown
MemberAuthor

Failures: cache timeout and Redox failure. Merging.

@dhardy
dhardy merged commit d877ed5 into rust-random:masterAug 28, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@dhardy@vks@newpavlov