complete: result
This commit is contained in:
parent
d830113fd4
commit
d1789a20c6
|
@ -1,8 +1,6 @@
|
||||||
// result1.rs
|
// result1.rs
|
||||||
// Make this test pass! Execute `rustlings hint result1` for hints :)
|
// Make this test pass! Execute `rustlings hint result1` for hints :)
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
struct PositiveNonzeroInteger(u64);
|
struct PositiveNonzeroInteger(u64);
|
||||||
|
|
||||||
|
@ -14,6 +12,11 @@ enum CreationError {
|
||||||
|
|
||||||
impl PositiveNonzeroInteger {
|
impl PositiveNonzeroInteger {
|
||||||
fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
|
fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
|
||||||
|
if value == 0 {
|
||||||
|
return Err(CreationError::Zero);
|
||||||
|
}else if value < 0 {
|
||||||
|
return Err(CreationError::Negative);
|
||||||
|
}
|
||||||
Ok(PositiveNonzeroInteger(value as u64))
|
Ok(PositiveNonzeroInteger(value as u64))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue