Currently, Uniform::new will panic on invalid parameters:
low >= high (or > for new_inclusive)
- (float, debug only) non-finite
low or high
- (float) non-finite
scale = high - low
Since #581 / #770, all other distributions with fallible constructor return a Result instead of panic (I think).
For: consistency and utility (error checking in derived types)
Against: this is another significant breaking change, when we hope to be getting close to stable (though now is certainly better than later)
Alternative: try_new, try_new_inclusive constructors - but this is inconsistent and results in far too many methods.
Also related: Rng::gen_range uses this. This should probably still panic on failure (note also Rng::fill vs Rng::try_fill; Rng::gen_bool and Rng::gen_ratio which may panic).
I suggest this error type:
enum Error {
/// Low > high, or equal in case of exclusive range
EmptyRange,
/// Input or range (high - low) is non-finite. Not relevant to integer types. In release mode only the range is checked.
NonFinite,
}
Link: #1165
Currently,
Uniform::newwill panic on invalid parameters:low >= high(or>fornew_inclusive)loworhighscale = high - lowSince #581 / #770, all other distributions with fallible constructor return a
Resultinstead of panic (I think).For: consistency and utility (error checking in derived types)
Against: this is another significant breaking change, when we hope to be getting close to stable (though now is certainly better than later)
Alternative:
try_new,try_new_inclusiveconstructors - but this is inconsistent and results in far too many methods.Also related:
Rng::gen_rangeuses this. This should probably still panic on failure (note alsoRng::fillvsRng::try_fill;Rng::gen_boolandRng::gen_ratiowhich may panic).I suggest this error type:
Link: #1165