File tree Expand file tree Collapse file tree 1 file changed +3
-18
lines changed
Expand file tree Collapse file tree 1 file changed +3
-18
lines changed Original file line number Diff line number Diff line change 11// errors3.rs
22// This is a program that is trying to use a completed version of the
3- // `total_cost` function from the previous exercise. It's not working though--
4- // we can't use the `?` operator in the `main()` function! Why not?
5- // What should we do instead? Scroll for hints!
3+ // `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!
65
76use std:: num:: ParseIntError ;
87
@@ -45,18 +44,4 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
4544
4645
4746
48- // Since the `?` operator returns an `Err` early if the thing it's trying to
49- // do fails, you can only use the `?` operator in functions that have a
50- // `Result` as their return type.
51-
52- // Hence the error that you get if you run this code is:
53-
54- // ```
55- // error[E0277]: the `?` operator can only be used in a function that returns `Result` (or another type that implements `std::ops::Try`)
56- // ```
57-
58- // So we have to use another way of handling a `Result` within `main`.
59-
60- // Decide what we should do if `pretend_user_input` has a string value that does
61- // not parse to an integer, and implement that instead of using the `?`
62- // operator.
47+ // If other functions can return a `Result`, why shouldn't `main`?
You can’t perform that action at this time.
0 commit comments