-
Notifications
You must be signed in to change notification settings - Fork 431
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
Make Uniform
constructors return a result
#1229
Conversation
This helps tools like `cargo geiger`.
- This is a breaking change. - The new error type had to be made public, otherwise `Uniform` could not be extended for user-defined types by implementing `UniformSampler`. - `rand_distr` was updated accordingly. - Also forbid unsafe code for crates where none is used. Fixes rust-random#1195, rust-random#1211.
@vks mind if I ping you on the status of this? |
@dhardy I'll try to have a look this Sunday. |
Skimming the above it looks like this should make |
I have a patch that is almost ready. |
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.
It's worth noting here that this PR introduces .unwrap()
in several distributions where it should be statically-verifiable that the range is non-empty, but of course the language doesn't let us do that.
/// Usually users should not call this directly but prefer to use | ||
/// [`Uniform::new`]. | ||
fn new<B1, B2>(low: B1, high: B2) -> Result<Self, Error> | ||
where | ||
B1: SampleBorrow<Self::X> + Sized, | ||
B2: SampleBorrow<Self::X> + Sized; | ||
|
||
/// Construct self, with inclusive bounds `[low, high]`. | ||
/// | ||
/// Usually users should not call this directly but instead use | ||
/// `Uniform::new_inclusive`, which asserts that `low <= high` before | ||
/// calling this. | ||
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Self | ||
/// Usually users should not call this directly but prefer to use | ||
/// [`Uniform::new_inclusive`]. | ||
fn new_inclusive<B1, B2>(low: B1, high: B2) -> Result<Self, 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.
There's not really a reason users shouldn't call these directly now (IIRC we used to have an assert in Uniform::new
), though Uniform::new
is probably still the more convenient API.
I'll try to look into it later this week. |
Sure. I used the web interface to make a merge commit, but it may be incorrect. |
Uniform
couldnot be extended for user-defined types by implementing
UniformSampler
.rand_distr
was updated accordingly.Fixes #1195, #1211.