summaryrefslogtreecommitdiff
path: root/exercises/13_error_handling/errors4.rs
diff options
context:
space:
mode:
authorMo <76752051+mo8it@users.noreply.github.com>2024-04-18 13:02:35 +0200
committerGitHub <noreply@github.com>2024-04-18 13:02:35 +0200
commit819dea250034a5658d0fe3306f6c35fc49961e17 (patch)
tree122060cdc0ef3f81d367e0afc7b0e3e9d29d33ee /exercises/13_error_handling/errors4.rs
parentc613b70363c60c6f4305d09c7394c96cdc6b69e4 (diff)
parent01e6732e4d920d9a1859e05fa28382e4307571af (diff)
Merge pull request #1949 from rust-lang/third-party-exercises
Support for third-party exercises
Diffstat (limited to 'exercises/13_error_handling/errors4.rs')
-rw-r--r--exercises/13_error_handling/errors4.rs30
1 files changed, 17 insertions, 13 deletions
diff --git a/exercises/13_error_handling/errors4.rs b/exercises/13_error_handling/errors4.rs
index 0e5c08b..993d42a 100644
--- a/exercises/13_error_handling/errors4.rs
+++ b/exercises/13_error_handling/errors4.rs
@@ -1,8 +1,3 @@
-// errors4.rs
-//
-// Execute `rustlings hint errors4` or use the `hint` watch subcommand for a
-// hint.
-
#[derive(PartialEq, Debug)]
struct PositiveNonzeroInteger(u64);
@@ -19,12 +14,21 @@ impl PositiveNonzeroInteger {
}
}
-#[test]
-fn test_creation() {
- assert!(PositiveNonzeroInteger::new(10).is_ok());
- assert_eq!(
- Err(CreationError::Negative),
- PositiveNonzeroInteger::new(-10)
- );
- assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0));
+fn main() {
+ // You can optionally experiment here.
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_creation() {
+ assert!(PositiveNonzeroInteger::new(10).is_ok());
+ assert_eq!(
+ Err(CreationError::Negative),
+ PositiveNonzeroInteger::new(-10)
+ );
+ assert_eq!(Err(CreationError::Zero), PositiveNonzeroInteger::new(0));
+ }
}