-
Notifications
You must be signed in to change notification settings - Fork 432
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 rand_core::Error in line with getrandom::Error #864
Conversation
So changing the error codes is not considered a breaking change for I'm fine with not copying the error descriptions, since I consider |
#[cfg(all(feature="getrandom", not(feature="std")))] { | ||
getrandom::Error::from(self.code).fmt(f) | ||
} | ||
#[cfg(not(feature="getrandom"))] { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std
implies getrandom
rand_core/src/error.rs
Outdated
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { | ||
self.inner.source() | ||
} | ||
} | ||
|
||
#[cfg(feature="std")] | ||
impl From<Error> for std::io::Error { | ||
#[inline] | ||
fn from(error: Error) -> Self { | ||
std::io::Error::new(std::io::ErrorKind::Other, error) |
There was a problem hiding this comment.
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?
if let Some(code) = error.raw_os_error() {
std::io::Error::from_raw_os_error(code)
} else {
std::io::Error::new(std::io::ErrorKind::Other, error)
}
@@ -10,24 +10,28 @@ | |||
use rand_core::Error; | |||
use core::fmt; | |||
|
|||
/// Base code for all `JitterRng` errors | |||
const ERROR_BASE: u32 = 0xAE53_0400; |
There was a problem hiding this comment.
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>
?
There was a problem hiding this comment.
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.
@newpavlov I added your suggestion; sorry about the delay. I think the other points you mentioned can be left? |
@dhardy Yes, they were just suggestions, so you can merge this PR as-is. |
Failures: cache timeout and Redox failure. Merging. |
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 ofrepr(u32)
on the enum (which I don't believe is a breaking change, since either way fore: TimerError
,e as u32
ande as isize
are supported, whileu32::from(e)
is not).Open question: should we copy
rand_jitter
error descriptions intorand_core
whencfg(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.