summaryrefslogtreecommitdiff
path: root/solutions/13_error_handling/errors4.rs
diff options
context:
space:
mode:
Diffstat (limited to 'solutions/13_error_handling/errors4.rs')
-rw-r--r--solutions/13_error_handling/errors4.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/solutions/13_error_handling/errors4.rs b/solutions/13_error_handling/errors4.rs
index f4d39bf..7f176cf 100644
--- a/solutions/13_error_handling/errors4.rs
+++ b/solutions/13_error_handling/errors4.rs
@@ -1,5 +1,3 @@
-#![allow(clippy::comparison_chain)]
-
#[derive(PartialEq, Debug)]
enum CreationError {
Negative,
@@ -11,12 +9,10 @@ struct PositiveNonzeroInteger(u64);
impl PositiveNonzeroInteger {
fn new(value: i64) -> Result<Self, CreationError> {
- if value == 0 {
- Err(CreationError::Zero)
- } else if value < 0 {
- Err(CreationError::Negative)
- } else {
- Ok(Self(value as u64))
+ match value.cmp(&0) {
+ Ordering::Less => Err(CreationError::Negative),
+ Ordering::Equal => Err(CreationError::Zero),
+ Ordering::Greater => Ok(Self(value as u64)),
}
}
}