Skip to content

Commit 9544ba1

Browse files
committed
Auto merge of #231 - rust-lang:refactor-hints, r=jrvidal
Refactor hints Breaking change. This removes hints from the end of files, and puts them into `info.toml`. You can now access hints using: ``` rustlings hint <exerciseName> ``` ALSO this changes the exercise system to index by name for `run` and `hint`, so: ``` rustlings run exercises/if/if1.rs ``` becomes ``` rustlings run if1 ```
2 parents 9a9007a + 1a7bb5a commit 9544ba1

Some content is hidden

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

48 files changed

+484
-1704
lines changed

exercises/enums/enums1.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// enums1.rs
2-
// Make me compile! Scroll down for hints!
2+
// Make me compile! Execute `rustlings hint enums1` for hints!
33

44
// I AM NOT DONE
55

@@ -14,31 +14,3 @@ fn main() {
1414
println!("{:?}", Message::Move);
1515
println!("{:?}", Message::ChangeColor);
1616
}
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
// Hint: The declaration of the enumeration type has not been defined yet.

exercises/enums/enums2.rs

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// enums2.rs
2-
// Make me compile! Scroll down for hints
2+
// Make me compile! Execute `rustlings hint enums2` for hints!
33

44
// I AM NOT DONE
55

@@ -26,38 +26,3 @@ fn main() {
2626
message.call();
2727
}
2828
}
29-
30-
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
// Hint: you can create enumerations that have different variants with different types
63-
// such as no data, anonymous structs, a single string, tuples, ...etc

exercises/error_handling/errors1.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// was, instead of just sometimes returning `None`. The 2nd test currently
55
// does not compile or pass, but it illustrates the behavior we would like
66
// this function to have.
7-
// Scroll down for hints!!!
7+
// Execute `rustlings hint errors1` for hints!
88

99
// I AM NOT DONE
1010

@@ -40,36 +40,3 @@ mod tests {
4040
);
4141
}
4242
}
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
// `Err` is one of the variants of `Result`, so what the 2nd test is saying
64-
// is that `generate_nametag_text` should return a `Result` instead of an
65-
// `Option`.
66-
67-
// To make this change, you'll need to:
68-
// - update the return type in the function signature to be a Result<String, String> that
69-
// could be the variants `Ok(String)` and `Err(String)`
70-
// - change the body of the function to return `Ok(stuff)` where it currently
71-
// returns `Some(stuff)`
72-
// - change the body of the function to return `Err(error message)` where it
73-
// currently returns `None`
74-
// - change the first test to expect `Ok(stuff)` where it currently expects
75-
// `Some(stuff)`.

exercises/error_handling/errors2.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// and add.
1515

1616
// There are at least two ways to implement this that are both correct-- but
17-
// one is a lot shorter! Scroll down for hints to both ways.
17+
// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways.
1818

1919
// I AM NOT DONE
2020

@@ -45,27 +45,3 @@ mod tests {
4545
);
4646
}
4747
}
48-
49-
50-
51-
52-
53-
54-
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
// One way to handle this is using a `match` statement on
66-
// `item_quantity.parse::<i32>()` where the cases are `Ok(something)` and
67-
// `Err(something)`. This pattern is very common in Rust, though, so there's
68-
// a `?` operator that does pretty much what you would make that match statement
69-
// do for you! Take a look at this section of the Error Handling chapter:
70-
// https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
71-
// and give it a try!

exercises/error_handling/errors3.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// errors3.rs
22
// This is a program that is trying to use a completed version of the
33
// `total_cost` function from the previous exercise. It's not working though!
4-
// Why not? What should we do to fix it? Scroll for hints!
4+
// Why not? What should we do to fix it?
5+
// Execute `rustlings hint errors3` for hints!
56

67
// I AM NOT DONE
78

@@ -28,22 +29,3 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
2829

2930
Ok(qty * cost_per_item + processing_fee)
3031
}
31-
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
// If other functions can return a `Result`, why shouldn't `main`?

exercises/error_handling/errorsn.rs

Lines changed: 1 addition & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// type goes where the question marks are, and how do we return
1414
// that type from the body of read_and_validate?
1515
//
16-
// Scroll down for hints :)
16+
// Execute `rustlings hint errorsn` for hints :)
1717

1818
// I AM NOT DONE
1919

@@ -112,138 +112,3 @@ impl error::Error for CreationError {
112112
}
113113
}
114114
}
115-
116-
117-
118-
119-
120-
121-
122-
123-
124-
125-
126-
127-
128-
129-
130-
131-
132-
133-
134-
135-
136-
137-
138-
139-
140-
141-
142-
143-
144-
145-
146-
// First hint: To figure out what type should go where the ??? is, take a look
147-
// at the test helper function `test_with_str`, since it returns whatever
148-
// `read_and_validate` returns and`test_with_str` has its signature fully
149-
// specified.
150-
151-
152-
153-
154-
155-
156-
157-
158-
159-
160-
161-
162-
163-
164-
165-
166-
167-
168-
169-
170-
// Next hint: There are three places in `read_and_validate` that we call a
171-
// function that returns a `Result` (that is, the functions might fail).
172-
// Apply the `?` operator on those calls so that we return immediately from
173-
// `read_and_validate` if those function calls fail.
174-
175-
176-
177-
178-
179-
180-
181-
182-
183-
184-
185-
186-
187-
188-
189-
190-
191-
192-
193-
194-
// Another hint: under the hood, the `?` operator calls `From::from`
195-
// on the error value to convert it to a boxed trait object, a Box<dyn error::Error>,
196-
// which is polymorphic-- that means that lots of different kinds of errors
197-
// can be returned from the same function because all errors act the same
198-
// since they all implement the `error::Error` trait.
199-
// Check out this section of the book:
200-
// https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-
214-
215-
216-
217-
218-
219-
220-
221-
// Another another hint: Note that because the `?` operator returns
222-
// the *unwrapped* value in the `Ok` case, if we want to return a `Result` from
223-
// `read_and_validate` for *its* success case, we'll have to rewrap a value
224-
// that we got from the return value of a `?`ed call in an `Ok`-- this will
225-
// look like `Ok(something)`.
226-
227-
228-
229-
230-
231-
232-
233-
234-
235-
236-
237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
// Another another another hint: `Result`s must be "used", that is, you'll
247-
// get a warning if you don't handle a `Result` that you get in your
248-
// function. Read more about that in the `std::result` module docs:
249-
// https://doc.rust-lang.org/std/result/#results-must-be-used

exercises/error_handling/option1.rs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// This example panics because the second time it calls `pop`, the `vec`
33
// is empty, so `pop` returns `None`, and `unwrap` panics if it's called
44
// on `None`. Handle this in a more graceful way than calling `unwrap`!
5-
// Scroll down for hints :)
5+
// Execute `rustlings hint option1` for hints :)
66

77
// I AM NOT DONE
88

@@ -29,31 +29,3 @@ mod tests {
2929
assert!(pop_too_much());
3030
}
3131
}
32-
33-
34-
35-
36-
37-
38-
39-
40-
41-
42-
43-
44-
45-
46-
47-
48-
49-
50-
51-
52-
53-
54-
55-
// Try using a `match` statement where the arms are `Some(thing)` and `None`.
56-
// Or set a default value to print out if you get `None` by using the
57-
// function `unwrap_or`.
58-
// Or use an `if let` statement on the result of `pop()` to both destructure
59-
// a `Some` value and only print out something if we have a value!

0 commit comments

Comments
 (0)