From 50ab289da6b9eb19a7486c341b00048c516b88c0 Mon Sep 17 00:00:00 2001 From: Taylor Yu Date: Sun, 6 Jun 2021 20:14:29 -0500 Subject: fix: rename result1 to errors4 Also put it in the ERROR HANDLING section where it probably belongs. --- exercises/error_handling/errors4.rs | 29 +++++++++++++++++++++++++++++ exercises/error_handling/result1.rs | 29 ----------------------------- info.toml | 20 ++++++++++---------- 3 files changed, 39 insertions(+), 39 deletions(-) create mode 100644 exercises/error_handling/errors4.rs delete mode 100644 exercises/error_handling/result1.rs diff --git a/exercises/error_handling/errors4.rs b/exercises/error_handling/errors4.rs new file mode 100644 index 0000000..0685c37 --- /dev/null +++ b/exercises/error_handling/errors4.rs @@ -0,0 +1,29 @@ +// errors4.rs +// Make this test pass! Execute `rustlings hint errors4` for hints :) + +// I AM NOT DONE + +#[derive(PartialEq, Debug)] +struct PositiveNonzeroInteger(u64); + +#[derive(PartialEq, Debug)] +enum CreationError { + Negative, + Zero, +} + +impl PositiveNonzeroInteger { + fn new(value: i64) -> Result { + Ok(PositiveNonzeroInteger(value as u64)) + } +} + +#[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)); +} diff --git a/exercises/error_handling/result1.rs b/exercises/error_handling/result1.rs deleted file mode 100644 index b978001..0000000 --- a/exercises/error_handling/result1.rs +++ /dev/null @@ -1,29 +0,0 @@ -// result1.rs -// Make this test pass! Execute `rustlings hint result1` for hints :) - -// I AM NOT DONE - -#[derive(PartialEq, Debug)] -struct PositiveNonzeroInteger(u64); - -#[derive(PartialEq, Debug)] -enum CreationError { - Negative, - Zero, -} - -impl PositiveNonzeroInteger { - fn new(value: i64) -> Result { - Ok(PositiveNonzeroInteger(value as u64)) - } -} - -#[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)); -} diff --git a/info.toml b/info.toml index 8c8f7c1..55875d7 100644 --- a/info.toml +++ b/info.toml @@ -489,6 +489,15 @@ mode = "compile" hint = """ If other functions can return a `Result`, why shouldn't `main`?""" +[[exercises]] +name = "errors4" +path = "exercises/error_handling/errors4.rs" +mode = "test" +hint = """ +`PositiveNonzeroInteger::new` is always creating a new instance and returning an `Ok` result. +It should be doing some checking, returning an `Err` result if those checks fail, and only +returning an `Ok` result if those checks determine that everything is... okay :)""" + [[exercises]] name = "errorsn" path = "exercises/error_handling/errorsn.rs" @@ -561,7 +570,7 @@ ReportCard struct generic, but also the correct property - you will need to chan of the struct slightly too...you can do it! """ -# OPTIONS / RESULTS +# OPTIONS [[exercises]] name = "option1" @@ -603,15 +612,6 @@ statement. How can this be avoided? The compiler shows the correction needed. After making the correction as suggested by the compiler, do read: https://doc.rust-lang.org/std/keyword.ref.html""" -[[exercises]] -name = "result1" -path = "exercises/error_handling/result1.rs" -mode = "test" -hint = """ -`PositiveNonzeroInteger::new` is always creating a new instance and returning an `Ok` result. -It should be doing some checking, returning an `Err` result if those checks fail, and only -returning an `Ok` result if those checks determine that everything is... okay :)""" - # TRAITS [[exercises]] -- cgit v1.2.3