From d1789a20c6796e244ac628e52ef5563305ac1c39 Mon Sep 17 00:00:00 2001 From: seth <yesifan66@gmail.com> Date: Wed, 23 Jun 2021 16:28:03 +0800 Subject: [PATCH] complete: result --- exercises/error_handling/result1.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/result1.rs index b978001..deb24d9 100644 --- a/exercises/error_handling/result1.rs +++ b/exercises/error_handling/result1.rs @@ -1,8 +1,6 @@ // result1.rs // Make this test pass! Execute `rustlings hint result1` for hints :) -// I AM NOT DONE - #[derive(PartialEq, Debug)] struct PositiveNonzeroInteger(u64); @@ -14,6 +12,11 @@ enum CreationError { impl PositiveNonzeroInteger { 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)) } }