Skip to content

Commit 74f44f5

Browse files
committed
feat(conversions): add hint comments
1 parent 8cfedb1 commit 74f44f5

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

exercises/conversions/from_into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// The From trait is used for value-to-value conversions.
22
// If From is implemented correctly for a type, the Into trait should work conversely.
33
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.From.html
4+
// Execute `rustlings hint from_into` or use the `hint` watch subcommand for a hint.
5+
46
#[derive(Debug)]
57
struct Person {
68
name: String,

exercises/conversions/from_str.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// Additionally, upon implementing FromStr, you can use the `parse` method
55
// on strings to generate an object of the implementor type.
66
// You can read more about it at https://doc.rust-lang.org/std/str/trait.FromStr.html
7+
// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint.
8+
79
use std::num::ParseIntError;
810
use std::str::FromStr;
911

@@ -37,6 +39,9 @@ enum ParsePersonError {
3739
// with something like `"4".parse::<usize>()`
3840
// 6. If while extracting the name and the age something goes wrong, an error should be returned
3941
// If everything goes well, then return a Result of a Person object
42+
//
43+
// As an aside: `Box<dyn Error>` implements `From<&'_ str>`. This means that if you want to return a
44+
// string error message, you can do so via just using return `Err("my error message".into())`.
4045

4146
impl FromStr for Person {
4247
type Err = ParsePersonError;

exercises/conversions/try_from_into.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// Basically, this is the same as From. The main difference is that this should return a Result type
44
// instead of the target type itself.
55
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
6+
// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a hint.
7+
68
use std::convert::{TryFrom, TryInto};
79

810
#[derive(Debug, PartialEq)]

exercises/conversions/using_as.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//
55
// The goal is to make sure that the division does not fail to compile
66
// and returns the proper type.
7+
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a hint.
78

89
// I AM NOT DONE
910

0 commit comments

Comments
 (0)