summaryrefslogtreecommitdiff
path: root/rustlings/exercises/13_error_handling/errors4.rs
diff options
context:
space:
mode:
authorHunter Kvalevog <hunter@kvog.sh>2026-09-27 12:11:32 -0500
committerHunter Kvalevog <hunter@kvog.sh>2026-09-27 12:11:32 -0500
commitb9b008c1d4a730335bdc9d465b0fdf7869fb09d4 (patch)
treee9695905445b4bab89c07b8662fe40207b74c288 /rustlings/exercises/13_error_handling/errors4.rs
parent1da0f56d76e5d5117eac05af092bf0ab58b14c8f (diff)
rustlings: complete 13
Diffstat (limited to 'rustlings/exercises/13_error_handling/errors4.rs')
-rw-r--r--rustlings/exercises/13_error_handling/errors4.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/rustlings/exercises/13_error_handling/errors4.rs b/rustlings/exercises/13_error_handling/errors4.rs
index 144fce7..e5f3d39 100644
--- a/rustlings/exercises/13_error_handling/errors4.rs
+++ b/rustlings/exercises/13_error_handling/errors4.rs
@@ -11,6 +11,12 @@ impl PositiveNonzeroInteger {
fn new(value: i64) -> Result<Self, CreationError> {
// TODO: This function shouldn't always return an `Ok`.
// Read the tests below to clarify what should be returned.
+ if value < 0 {
+ return Err(CreationError::Negative);
+ }
+ if value == 0 {
+ return Err(CreationError::Zero);
+ }
Ok(Self(value as u64))
}
}