aboutsummaryrefslogtreecommitdiffstats
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
commit7881b3aedb24ccabb5d5ecfa904d0ea4a8d447f6 (patch)
treee9695905445b4bab89c07b8662fe40207b74c288 /rustlings/exercises/13_error_handling/errors4.rs
parentc39a2a475b7338269e6686217011dade073fa31d (diff)
downloaddemos-7881b3aedb24ccabb5d5ecfa904d0ea4a8d447f6.tar.gz
demos-7881b3aedb24ccabb5d5ecfa904d0ea4a8d447f6.zip
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))
}
}