From c34e2adcbb261f71fbd013d61257457dd84bd849 Mon Sep 17 00:00:00 2001 From: mokou Date: Thu, 14 Jul 2022 18:02:33 +0200 Subject: [PATCH] feat(errors): Improve comments and hints --- exercises/error_handling/errors1.rs | 2 +- exercises/error_handling/errors2.rs | 3 ++- exercises/error_handling/errors3.rs | 2 +- exercises/error_handling/errors4.rs | 3 ++- exercises/error_handling/errors5.rs | 2 +- exercises/error_handling/errors6.rs | 6 +++++- info.toml | 5 ++++- 7 files changed, 16 insertions(+), 7 deletions(-) diff --git a/exercises/error_handling/errors1.rs b/exercises/error_handling/errors1.rs index 1a2a857..bcee972 100644 --- a/exercises/error_handling/errors1.rs +++ b/exercises/error_handling/errors1.rs @@ -3,7 +3,7 @@ // you pass it an empty string. It'd be nicer if it explained what the problem // was, instead of just sometimes returning `None`. Thankfully, Rust has a similar // construct to `Option` that can be used to express error conditions. Let's use it! -// Execute `rustlings hint errors1` for hints! +// Execute `rustlings hint errors1` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors2.rs b/exercises/error_handling/errors2.rs index aad3a93..1cd8fc6 100644 --- a/exercises/error_handling/errors2.rs +++ b/exercises/error_handling/errors2.rs @@ -14,7 +14,8 @@ // and add. // There are at least two ways to implement this that are both correct-- but -// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways. +// one is a lot shorter! +// Execute `rustlings hint errors2` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors3.rs b/exercises/error_handling/errors3.rs index 460ac5c..a2d2d19 100644 --- a/exercises/error_handling/errors3.rs +++ b/exercises/error_handling/errors3.rs @@ -2,7 +2,7 @@ // This is a program that is trying to use a completed version of the // `total_cost` function from the previous exercise. It's not working though! // Why not? What should we do to fix it? -// Execute `rustlings hint errors3` for hints! +// Execute `rustlings hint errors3` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors4.rs b/exercises/error_handling/errors4.rs index 0685c37..0efe8cc 100644 --- a/exercises/error_handling/errors4.rs +++ b/exercises/error_handling/errors4.rs @@ -1,5 +1,5 @@ // errors4.rs -// Make this test pass! Execute `rustlings hint errors4` for hints :) +// Execute `rustlings hint errors4` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -14,6 +14,7 @@ enum CreationError { impl PositiveNonzeroInteger { fn new(value: i64) -> Result { + // Hmm...? Why is this only returning an Ok value? Ok(PositiveNonzeroInteger(value as u64)) } } diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs index 9d5ee4b..67411c5 100644 --- a/exercises/error_handling/errors5.rs +++ b/exercises/error_handling/errors5.rs @@ -12,7 +12,7 @@ // What can we use to describe both errors? In other words, is there a trait which both errors implement? -// Execute `rustlings hint errors5` for hints! +// Execute `rustlings hint errors5` or use the `hint` watch subcommand for a hint. // I AM NOT DONE diff --git a/exercises/error_handling/errors6.rs b/exercises/error_handling/errors6.rs index 847a049..1306fb0 100644 --- a/exercises/error_handling/errors6.rs +++ b/exercises/error_handling/errors6.rs @@ -6,7 +6,7 @@ // we define a custom error type to make it possible for callers to decide // what to do next when our function returns an error. -// Make these tests pass! Execute `rustlings hint errors6` for hints :) +// Execute `rustlings hint errors6` or use the `hint` watch subcommand for a hint. // I AM NOT DONE @@ -20,7 +20,11 @@ enum ParsePosNonzeroError { } impl ParsePosNonzeroError { + fn from_creation(err: CreationError) -> ParsePosNonzeroError { + ParsePosNonzeroError::Creation(err) + } // TODO: add another error conversion function here. + // fn from_parseint... } fn parse_pos_nonzero(s: &str) diff --git a/info.toml b/info.toml index 97c174f..cb49a97 100644 --- a/info.toml +++ b/info.toml @@ -603,7 +603,10 @@ name = "errors3" path = "exercises/error_handling/errors3.rs" mode = "compile" hint = """ -If other functions can return a `Result`, why shouldn't `main`?""" +If other functions can return a `Result`, why shouldn't `main`? It's a fairly common +convention to return something like Result<(), ErrorType> from your main function. +The unit (`()`) type is there because nothing is really needed in terms of positive +results.""" [[exercises]] name = "errors4"