Skip to content

Commit c3e7b83

Browse files
committed
fix: use trait objects for from_str
Use `Box<dyn error::Error>` to allow solutions to use `?` to propagate errors.
1 parent 2e93a58 commit c3e7b83

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

exercises/conversions/from_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Additionally, upon implementing FromStr, you can use the `parse` method
33
// on strings to generate an object of the implementor type.
44
// You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html
5+
use std::error;
56
use std::str::FromStr;
67

78
#[derive(Debug)]
@@ -23,7 +24,7 @@ struct Person {
2324
// If everything goes well, then return a Result of a Person object
2425

2526
impl FromStr for Person {
26-
type Err = String;
27+
type Err = Box<dyn error::Error>;
2728
fn from_str(s: &str) -> Result<Person, Self::Err> {
2829
}
2930
}

info.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,5 +884,5 @@ path = "exercises/conversions/from_str.rs"
884884
mode = "test"
885885
hint = """
886886
The implementation of FromStr should return an Ok with a Person object,
887-
or an Err with a string if the string is not valid.
887+
or an Err with an error if the string is not valid.
888888
This is almost like the `try_from_into` exercise."""

0 commit comments

Comments
 (0)