Skip to content

Commit 132d5ca

Browse files
authored
Merge pull request #1535 from robertefry/comment_cleanup
docs: cleanup the explanation paragraphs at the start of each exercise.
2 parents 4cfcf2c + b44472b commit 132d5ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+577
-337
lines changed

exercises/clippy/clippy1.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// clippy1.rs
2-
// The Clippy tool is a collection of lints to analyze your code
3-
// so you can catch common mistakes and improve your Rust code.
42
//
5-
// For these exercises the code will fail to compile when there are clippy warnings
6-
// check clippy's suggestions from the output to solve the exercise.
7-
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a hint.
3+
// The Clippy tool is a collection of lints to analyze your code so you can
4+
// catch common mistakes and improve your Rust code.
5+
//
6+
// For these exercises the code will fail to compile when there are clippy
7+
// warnings check clippy's suggestions from the output to solve the exercise.
8+
//
9+
// Execute `rustlings hint clippy1` or use the `hint` watch subcommand for a
10+
// hint.
811

912
// I AM NOT DONE
1013

exercises/clippy/clippy2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// clippy2.rs
2-
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a hint.
2+
//
3+
// Execute `rustlings hint clippy2` or use the `hint` watch subcommand for a
4+
// hint.
35

46
// I AM NOT DONE
57

exercises/clippy/clippy3.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// clippy3.rs
2+
//
23
// Here's a couple more easy Clippy fixes, so you can see its utility.
4+
//
5+
// Execute `rustlings hint clippy3` or use the `hint` watch subcommand for a hint.
36

47
// I AM NOT DONE
58

exercises/conversions/as_ref_mut.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// AsRef and AsMut allow for cheap reference-to-reference conversions.
2-
// Read more about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html
3-
// and https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
4-
// Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a hint.
1+
// as_ref_mut.rs
2+
//
3+
// AsRef and AsMut allow for cheap reference-to-reference conversions. Read more
4+
// about them at https://doc.rust-lang.org/std/convert/trait.AsRef.html and
5+
// https://doc.rust-lang.org/std/convert/trait.AsMut.html, respectively.
6+
//
7+
// Execute `rustlings hint as_ref_mut` or use the `hint` watch subcommand for a
8+
// hint.
59

610
// I AM NOT DONE
711

exercises/conversions/from_into.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
// The From trait is used for value-to-value conversions.
2-
// If From is implemented correctly for a type, the Into trait should work conversely.
3-
// 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.
1+
// from_into.rs
2+
//
3+
// The From trait is used for value-to-value conversions. If From is implemented
4+
// correctly for a type, the Into trait should work conversely. You can read
5+
// more about it at https://doc.rust-lang.org/std/convert/trait.From.html
6+
//
7+
// Execute `rustlings hint from_into` or use the `hint` watch subcommand for a
8+
// hint.
59

610
#[derive(Debug)]
711
struct Person {
@@ -20,20 +24,21 @@ impl Default for Person {
2024
}
2125
}
2226

23-
// Your task is to complete this implementation
24-
// in order for the line `let p = Person::from("Mark,20")` to compile
25-
// Please note that you'll need to parse the age component into a `usize`
26-
// with something like `"4".parse::<usize>()`. The outcome of this needs to
27-
// be handled appropriately.
27+
// Your task is to complete this implementation in order for the line `let p =
28+
// Person::from("Mark,20")` to compile Please note that you'll need to parse the
29+
// age component into a `usize` with something like `"4".parse::<usize>()`. The
30+
// outcome of this needs to be handled appropriately.
2831
//
2932
// Steps:
30-
// 1. If the length of the provided string is 0, then return the default of Person
31-
// 2. Split the given string on the commas present in it
32-
// 3. Extract the first element from the split operation and use it as the name
33-
// 4. If the name is empty, then return the default of Person
34-
// 5. Extract the other element from the split operation and parse it into a `usize` as the age
35-
// If while parsing the age, something goes wrong, then return the default of Person
36-
// Otherwise, then return an instantiated Person object with the results
33+
// 1. If the length of the provided string is 0, then return the default of
34+
// Person.
35+
// 2. Split the given string on the commas present in it.
36+
// 3. Extract the first element from the split operation and use it as the name.
37+
// 4. If the name is empty, then return the default of Person.
38+
// 5. Extract the other element from the split operation and parse it into a
39+
// `usize` as the age.
40+
// If while parsing the age, something goes wrong, then return the default of
41+
// Person Otherwise, then return an instantiated Person object with the results
3742

3843
// I AM NOT DONE
3944

@@ -77,7 +82,8 @@ mod tests {
7782
}
7883
#[test]
7984
fn test_bad_age() {
80-
// Test that "Mark,twenty" will return the default person due to an error in parsing age
85+
// Test that "Mark,twenty" will return the default person due to an
86+
// error in parsing age
8187
let p = Person::from("Mark,twenty");
8288
assert_eq!(p.name, "John");
8389
assert_eq!(p.age, 30);

exercises/conversions/from_str.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// from_str.rs
2-
// This is similar to from_into.rs, but this time we'll implement `FromStr`
3-
// and return errors instead of falling back to a default value.
4-
// Additionally, upon implementing FromStr, you can use the `parse` method
5-
// on strings to generate an object of the implementor type.
6-
// 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.
2+
//
3+
// This is similar to from_into.rs, but this time we'll implement `FromStr` and
4+
// return errors instead of falling back to a default value. Additionally, upon
5+
// implementing FromStr, you can use the `parse` method on strings to generate
6+
// an object of the implementor type. You can read more about it at
7+
// https://doc.rust-lang.org/std/str/trait.FromStr.html
8+
//
9+
// Execute `rustlings hint from_str` or use the `hint` watch subcommand for a
10+
// hint.
811

912
use std::num::ParseIntError;
1013
use std::str::FromStr;
@@ -33,15 +36,18 @@ enum ParsePersonError {
3336
// Steps:
3437
// 1. If the length of the provided string is 0, an error should be returned
3538
// 2. Split the given string on the commas present in it
36-
// 3. Only 2 elements should be returned from the split, otherwise return an error
39+
// 3. Only 2 elements should be returned from the split, otherwise return an
40+
// error
3741
// 4. Extract the first element from the split operation and use it as the name
38-
// 5. Extract the other element from the split operation and parse it into a `usize` as the age
39-
// with something like `"4".parse::<usize>()`
40-
// 6. If while extracting the name and the age something goes wrong, an error should be returned
42+
// 5. Extract the other element from the split operation and parse it into a
43+
// `usize` as the age with something like `"4".parse::<usize>()`
44+
// 6. If while extracting the name and the age something goes wrong, an error
45+
// should be returned
4146
// If everything goes well, then return a Result of a Person object
4247
//
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())`.
48+
// As an aside: `Box<dyn Error>` implements `From<&'_ str>`. This means that if
49+
// you want to return a string error message, you can do so via just using
50+
// return `Err("my error message".into())`.
4551

4652
impl FromStr for Person {
4753
type Err = ParsePersonError;

exercises/conversions/try_from_into.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
// try_from_into.rs
2-
// TryFrom is a simple and safe type conversion that may fail in a controlled way under some circumstances.
3-
// Basically, this is the same as From. The main difference is that this should return a Result type
4-
// instead of the target type itself.
5-
// You can read more about it at https://doc.rust-lang.org/std/convert/trait.TryFrom.html
6-
// Execute `rustlings hint try_from_into` or use the `hint` watch subcommand for a hint.
2+
//
3+
// TryFrom is a simple and safe type conversion that may fail in a controlled
4+
// way under some circumstances. Basically, this is the same as From. The main
5+
// difference is that this should return a Result type instead of the target
6+
// type itself. You can read more about it at
7+
// https://doc.rust-lang.org/std/convert/trait.TryFrom.html
8+
//
9+
// Execute `rustlings hint try_from_into` or use the `hint` watch subcommand for
10+
// a hint.
711

812
use std::convert::{TryFrom, TryInto};
913

@@ -25,14 +29,13 @@ enum IntoColorError {
2529

2630
// I AM NOT DONE
2731

28-
// Your task is to complete this implementation
29-
// and return an Ok result of inner type Color.
30-
// You need to create an implementation for a tuple of three integers,
31-
// an array of three integers, and a slice of integers.
32+
// Your task is to complete this implementation and return an Ok result of inner
33+
// type Color. You need to create an implementation for a tuple of three
34+
// integers, an array of three integers, and a slice of integers.
3235
//
33-
// Note that the implementation for tuple and array will be checked at compile time,
34-
// but the slice implementation needs to check the slice length!
35-
// Also note that correct RGB color values must be integers in the 0..=255 range.
36+
// Note that the implementation for tuple and array will be checked at compile
37+
// time, but the slice implementation needs to check the slice length! Also note
38+
// that correct RGB color values must be integers in the 0..=255 range.
3639

3740
// Tuple implementation
3841
impl TryFrom<(i16, i16, i16)> for Color {

exercises/conversions/using_as.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
// Type casting in Rust is done via the usage of the `as` operator.
2-
// Please note that the `as` operator is not only used when type casting.
3-
// It also helps with renaming imports.
1+
// using_as.rs
42
//
5-
// The goal is to make sure that the division does not fail to compile
6-
// and returns the proper type.
7-
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a hint.
3+
// Type casting in Rust is done via the usage of the `as` operator. Please note
4+
// that the `as` operator is not only used when type casting. It also helps with
5+
// renaming imports.
6+
//
7+
// The goal is to make sure that the division does not fail to compile and
8+
// returns the proper type.
9+
//
10+
// Execute `rustlings hint using_as` or use the `hint` watch subcommand for a
11+
// hint.
812

913
// I AM NOT DONE
1014

exercises/enums/enums1.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// enums1.rs
2+
//
23
// No hints this time! ;)
34

45
// I AM NOT DONE

exercises/enums/enums2.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// enums2.rs
2-
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a hint.
2+
//
3+
// Execute `rustlings hint enums2` or use the `hint` watch subcommand for a
4+
// hint.
35

46
// I AM NOT DONE
57

0 commit comments

Comments
 (0)