Skip to content
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

ErrorKind::Input #535

Closed
dhardy opened this issue Jun 29, 2018 · 3 comments · Fixed by #547
Closed

ErrorKind::Input #535

dhardy opened this issue Jun 29, 2018 · 3 comments · Fixed by #547

Comments

@dhardy
Copy link
Member

dhardy commented Jun 29, 2018

ErrorKind was designed with RNG errors in mind, but has also found some use in other code (#518). I suggest we add a new enum variant: Input (or InvalidInput or UserInput or something), meaning that a function was called with invalid parameters.

@dhardy
Copy link
Member Author

dhardy commented Jul 1, 2018

Regarding weighted sampling:

@sicking's #518 introduced fn choose_weighted<R, F, B, X>(&self, rng: &mut R, weight: F) -> Option<&Self::Item>, but does not address error handling of these convenience methods

https://github.com/rust-lang-nursery/rand/blob/0faff206d21515e3fd5233cfbd6899efd673a46b/src/seq.rs#L112

I think the best option would be to change the return type to Result<&Self::Item, WeightedError> where:

enum WeightedError {
    NoItem,
    InvalidWeights,
}

impl From<WeightedError> for Error { .. }

or similar (possibly separate variants for negative weights, zero weights and no weights?).

WeightedIndex::new should probably return the same error type.

@dhardy
Copy link
Member Author

dhardy commented Jul 7, 2018

@sicking you offered to look into this I think?

@sicking
Copy link
Contributor

sicking commented Jul 10, 2018

I'll definitely get to this this week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants