Skip to content

Commit

Permalink
Merge branch 'master' into impl-error-for-distr-error
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Dec 28, 2019
2 parents 68816c7 + 5643fd5 commit 59df78f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
2 changes: 2 additions & 0 deletions rand_distr/benches/distributions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#![feature(test)]

extern crate test;

const RAND_BENCH_N: u64 = 1000;

use std::mem::size_of;
Expand Down
24 changes: 7 additions & 17 deletions src/distributions/weighted/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,16 @@ pub enum WeightedError {
TooMany,
}

impl WeightedError {
fn msg(&self) -> &str {
match *self {
WeightedError::NoItem => "No weights provided.",
WeightedError::InvalidWeight => "A weight is invalid.",
WeightedError::AllWeightsZero => "All weights are zero.",
WeightedError::TooMany => "Too many weights (hit u32::MAX)",
}
}
}

#[cfg(feature="std")]
impl ::std::error::Error for WeightedError {
fn description(&self) -> &str {
self.msg()
}
}
impl ::std::error::Error for WeightedError {}

impl fmt::Display for WeightedError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.msg())
match *self {
WeightedError::NoItem => write!(f, "No weights provided."),
WeightedError::InvalidWeight => write!(f, "A weight is invalid."),
WeightedError::AllWeightsZero => write!(f, "All weights are zero."),
WeightedError::TooMany => write!(f, "Too many weights (hit u32::MAX)"),
}
}
}

0 comments on commit 59df78f

Please sign in to comment.