summaryrefslogtreecommitdiff
path: root/exercises
diff options
context:
space:
mode:
authorNoah Cairns <noah.cairns1@gmail.com>2022-06-15 09:40:30 -0400
committermokou <mokou@fastmail.com>2022-07-14 17:59:29 +0200
commit5e1ca4b99577578a1c92d71eeba49d88f60dcedc (patch)
tree96b4797dd5347cfc7382cc044d3f9a6b17d96775 /exercises
parent582320aded8a9369f8b5a959419f04ea6d3f5b04 (diff)
fix(errors5): improve exercise instructions
Diffstat (limited to 'exercises')
-rw-r--r--exercises/error_handling/errors5.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/exercises/error_handling/errors5.rs b/exercises/error_handling/errors5.rs
index 365a869..9d5ee4b 100644
--- a/exercises/error_handling/errors5.rs
+++ b/exercises/error_handling/errors5.rs
@@ -1,7 +1,17 @@
// errors5.rs
-// This program uses a completed version of the code from errors4.
-// It won't compile right now! Why?
+// This program uses an altered version of the code from errors4.
+
+// This exercise uses some concepts that we won't get to until later in the course, like `Box` and the
+// `From` trait. It's not important to understand them in detail right now, but you can read ahead if you like.
+
+// In short, this particular use case for boxes is for when you want to own a value and you care only that it is a
+// type which implements a particular trait. To do so, The Box is declared as of type Box<dyn Trait> where Trait is the trait
+// the compiler looks for on any value used in that context. For this exercise, that context is the potential errors
+// which can be returned in a Result.
+
+// 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!
// I AM NOT DONE
@@ -11,7 +21,7 @@ use std::fmt;
use std::num::ParseIntError;
// TODO: update the return type of `main()` to make this compile.
-fn main() -> Result<(), ParseIntError> {
+fn main() -> Result<(), Box<dyn ???>> {
let pretend_user_input = "42";
let x: i64 = pretend_user_input.parse()?;
println!("output={:?}", PositiveNonzeroInteger::new(x)?);