Uh oh!
There was an error while loading. Please reload this page.
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. Fixesrust-random#1195, rust-random#1211.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
dhardy
commented
Aug 3, 2022
@vks mind if I ping you on the status of this? |
vks
commented
Aug 3, 2022
@dhardy I'll try to have a look this Sunday. |
dhardy
commented
Dec 6, 2022
Skimming the above it looks like this should make |
vks
commented
Dec 6, 2022
I have a patch that is almost ready. |
dhardy
left a comment
There was a problem hiding this comment.
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.
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.
dhardy
commented
Dec 7, 2022
vks
commented
Dec 11, 2022
I'll try to look into it later this week. |
dhardy
commented
Dec 11, 2022
Sure. I used the web interface to make a merge commit, but it may be incorrect. |
Uh oh!
There was an error while loading. Please reload this page.
* Forbid unsafe code in crates without unsafe code This helps tools like `cargo geiger`. * Make `Uniform` constructors return a result - 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. Fixesrust-random#1195, rust-random#1211. * Address review feedback * Make `sample_single` return a `Result` * Fix benchmarks * Small fixes * Update src/distributions/uniform.rs
* Forbid unsafe code in crates without unsafe code This helps tools like `cargo geiger`. * Make `Uniform` constructors return a result - 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. Fixesrust-random#1195, rust-random#1211. * Address review feedback * Make `sample_single` return a `Result` * Fix benchmarks * Small fixes * Update src/distributions/uniform.rs
Uniformcouldnot be extended for user-defined types by implementing
UniformSampler.rand_distrwas updated accordingly.Fixes#1195, #1211.