mirror of
https://github.com/notohh/rustlings.git
synced 2024-12-18 06:58:10 -05:00
Use match instead of comparison chain
This commit is contained in:
parent
bedf0789f2
commit
423b50b068
2 changed files with 4 additions and 10 deletions
|
@ -1,5 +1,3 @@
|
||||||
#![allow(clippy::comparison_chain)]
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
enum CreationError {
|
enum CreationError {
|
||||||
Negative,
|
Negative,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
#![allow(clippy::comparison_chain)]
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
enum CreationError {
|
enum CreationError {
|
||||||
Negative,
|
Negative,
|
||||||
|
@ -11,12 +9,10 @@ struct PositiveNonzeroInteger(u64);
|
||||||
|
|
||||||
impl PositiveNonzeroInteger {
|
impl PositiveNonzeroInteger {
|
||||||
fn new(value: i64) -> Result<Self, CreationError> {
|
fn new(value: i64) -> Result<Self, CreationError> {
|
||||||
if value == 0 {
|
match value.cmp(&0) {
|
||||||
Err(CreationError::Zero)
|
Ordering::Less => Err(CreationError::Negative),
|
||||||
} else if value < 0 {
|
Ordering::Equal => Err(CreationError::Zero),
|
||||||
Err(CreationError::Negative)
|
Ordering::Greater => Ok(Self(value as u64)),
|
||||||
} else {
|
|
||||||
Ok(Self(value as u64))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue