Skip to content

Commit

Permalink
Merge pull request #920 from AnderEnder/remove-deprecated-error-descr…
Browse files Browse the repository at this point in the history
…iption

Remove deprecated Error::description and Error::cause
  • Loading branch information
dhardy committed Dec 27, 2019
2 parents 1096cdb + d186bc5 commit 5643fd5
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/distributions/weighted/mod.rs
Expand Up @@ -364,29 +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()
}
fn cause(&self) -> Option<&dyn (::std::error::Error)> {
None
}
}
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 5643fd5

Please sign in to comment.