You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Many distributions currently panic when given invalid parameters:
implExp{/// Construct a new `Exp` with the given shape parameter/// `lambda`. Panics if `lambda <= 0`.#[inline]pubfnnew(lambda:f64) -> Exp{assert!(lambda > 0.0,"Exp::new called with `lambda` <= 0");Exp{lambda_inverse:1.0 / lambda }}}
In contrast, quite a few parts of the library return a Result from the ctor. Notably:
impl<X:SampleUniform + PartialOrd>WeightedIndex<X>{/// Creates a new a `WeightedIndex` [`Distribution`] ...pubfnnew<I>(weights:I) -> Result<WeightedIndex<X>,WeightedError>where ... {}}/// Error type returned from `WeightedIndex::new`.#[derive(Debug,Clone,Copy,PartialEq,Eq)]pubenumWeightedError{/// The provided iterator contained no items.NoItem,/// A weight lower than zero was used.NegativeWeight,/// All items in the provided iterator had a weight of zero.AllWeightsZero,}
@vks suggested adding try_new ctors to avoid breakage, but due to #290 proposing to move these to rand_stat there will be some breakage anyway. So which is better?
fn new(...) -> Self only (status quo) — not ideal for parameters which must be checked at run-time
fn new(...) -> Result<Self, ...> only — requires error handling or .unwrap()
I'm leaning towards the latter despite the breakage. Lots of redundant API functions just for slightly better ergonomics isn't good style and I don't think the breakage is a big deal.
The text was updated successfully, but these errors were encountered:
@vks suggested adding try_new ctors to avoid breakage, but due to #290 proposing to move these to rand_stat there will be some breakage anyway.
What breakage? If we reexport rand_stat as rand::distributions there should not be any breakage.
I'm leaning towards the latter despite the breakage. Lots of redundant API functions just for slightly better ergonomics isn't good style and I don't think the breakage is a big deal.
I agree. I think this breakage is much easier to fix (by adding .unwrap()) than many of our previous breakages.
Many distributions currently panic when given invalid parameters:
In contrast, quite a few parts of the library return a
Result
from the ctor. Notably:@vks suggested adding
try_new
ctors to avoid breakage, but due to #290 proposing to move these torand_stat
there will be some breakage anyway. So which is better?fn new(...) -> Self
andfn try_new(...) -> Result<Self, ...>
ctorsfn new(...) -> Self
only (status quo) — not ideal for parameters which must be checked at run-timefn new(...) -> Result<Self, ...>
only — requires error handling or.unwrap()
I'm leaning towards the latter despite the breakage. Lots of redundant API functions just for slightly better ergonomics isn't good style and I don't think the breakage is a big deal.
The text was updated successfully, but these errors were encountered: