From 27545fe9640e3c3c90786b6a3cad37cb0f838ea2 Mon Sep 17 00:00:00 2001
From: David Bailey <davidbailey00@outlook.com>
Date: Sat, 16 Jan 2021 20:43:34 +0000
Subject: [PATCH] Add result1 solution

---
 exercises/error_handling/result1.rs | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/result1.rs
index b978001..952b46d 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,7 +12,13 @@ enum CreationError {
 
 impl PositiveNonzeroInteger {
     fn new(value: i64) -> Result<PositiveNonzeroInteger, CreationError> {
-        Ok(PositiveNonzeroInteger(value as u64))
+        if value == 0 {
+            Err(CreationError::Zero)
+        } else if value < 0 {
+            Err(CreationError::Negative)
+        } else {
+            Ok(PositiveNonzeroInteger(value as u64))
+        }
     }
 }