feat(errors): completed errors

This commit is contained in:
2026-09-06 22:26:34 +02:00
parent ad542a4892
commit fe01747f82
6 changed files with 16 additions and 8 deletions
+7 -1
View File
@@ -1,3 +1,5 @@
use std::cmp::Ordering;
#[derive(PartialEq, Debug)]
enum CreationError {
Negative,
@@ -11,7 +13,11 @@ 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.
Ok(Self(value as u64))
match value.cmp(&0) {
Ordering::Less => Err(CreationError::Negative),
Ordering::Equal => Err(CreationError::Zero),
Ordering::Greater => Ok(Self(value as u64)),
}
}
}