@@ -117,8 +117,8 @@ the first example. This is because the
117117panic is embedded in the calls to ` unwrap ` .
118118
119119To “unwrap” something in Rust is to say, “Give me the result of the
120- computation, and if there was an error, just panic and stop the program.”
121- It would be better if we just showed the code for unwrapping because it is so
120+ computation, and if there was an error, panic and stop the program.”
121+ It would be better if we showed the code for unwrapping because it is so
122122simple, but to do that, we will first need to explore the ` Option ` and ` Result `
123123types. Both of these types have a method called ` unwrap ` defined on them.
124124
@@ -154,7 +154,7 @@ fn find(haystack: &str, needle: char) -> Option<usize> {
154154}
155155```
156156
157- Notice that when this function finds a matching character, it doesn't just
157+ Notice that when this function finds a matching character, it doesn't only
158158return the ` offset ` . Instead, it returns ` Some(offset) ` . ` Some ` is a variant or
159159a * value constructor* for the ` Option ` type. You can think of it as a function
160160with the type ` fn<T>(value: T) -> Option<T> ` . Correspondingly, ` None ` is also a
@@ -216,7 +216,7 @@ we saw how to use `find` to discover the extension in a file name. Of course,
216216not all file names have a ` . ` in them, so it's possible that the file name has
217217no extension. This * possibility of absence* is encoded into the types using
218218` Option<T> ` . In other words, the compiler will force us to address the
219- possibility that an extension does not exist. In our case, we just print out a
219+ possibility that an extension does not exist. In our case, we only print out a
220220message saying as such.
221221
222222Getting the extension of a file name is a pretty common operation, so it makes
@@ -248,7 +248,7 @@ tiresome.
248248
249249In fact, the case analysis in ` extension_explicit ` follows a very common
250250pattern: * map* a function on to the value inside of an ` Option<T> ` , unless the
251- option is ` None ` , in which case, just return ` None ` .
251+ option is ` None ` , in which case, return ` None ` .
252252
253253Rust has parametric polymorphism, so it is very easy to define a combinator
254254that abstracts this pattern:
@@ -350,7 +350,7 @@ fn file_name(file_path: &str) -> Option<&str> {
350350}
351351```
352352
353- You might think that we could just use the ` map ` combinator to reduce the case
353+ You might think that we could use the ` map ` combinator to reduce the case
354354analysis, but its type doesn't quite fit. Namely, ` map ` takes a function that
355355does something only with the inner value. The result of that function is then
356356* always* [ rewrapped with ` Some ` ] ( #code-option-map ) . Instead, we need something
@@ -670,7 +670,7 @@ The tricky aspect here is that `argv.nth(1)` produces an `Option` while
670670with both an ` Option ` and a ` Result ` , the solution is * usually* to convert the
671671` Option ` to a ` Result ` . In our case, the absence of a command line parameter
672672(from ` env::args() ` ) means the user didn't invoke the program correctly. We
673- could just use a ` String ` to describe the error. Let's try:
673+ could use a ` String ` to describe the error. Let's try:
674674
675675<span id =" code-error-double-string " ></span >
676676
@@ -709,7 +709,7 @@ fn ok_or<T, E>(option: Option<T>, err: E) -> Result<T, E> {
709709
710710The other new combinator used here is
711711[ ` Result::map_err ` ] ( ../std/result/enum.Result.html#method.map_err ) .
712- This is just like ` Result::map ` , except it maps a function on to the * error*
712+ This is like ` Result::map ` , except it maps a function on to the * error*
713713portion of a ` Result ` value. If the ` Result ` is an ` Ok(...) ` value, then it is
714714returned unmodified.
715715
@@ -841,7 +841,7 @@ example, the very last call to `map` multiplies the `Ok(...)` value (which is
841841an ` i32 ` ) by ` 2 ` . If an error had occurred before that point, this operation
842842would have been skipped because of how ` map ` is defined.
843843
844- ` map_err ` is the trick that makes all of this work. ` map_err ` is just like
844+ ` map_err ` is the trick that makes all of this work. ` map_err ` is like
845845` map ` , except it applies a function to the ` Err(...) ` value of a ` Result ` . In
846846this case, we want to convert all of our errors to one type: ` String ` . Since
847847both ` io::Error ` and ` num::ParseIntError ` implement ` ToString ` , we can call the
@@ -901,7 +901,7 @@ reduce explicit case analysis. Combinators aren't the only way.
901901## The ` try! ` macro
902902
903903A cornerstone of error handling in Rust is the ` try! ` macro. The ` try! ` macro
904- abstracts case analysis just like combinators, but unlike combinators, it also
904+ abstracts case analysis like combinators, but unlike combinators, it also
905905abstracts * control flow* . Namely, it can abstract the * early return* pattern
906906seen above.
907907
@@ -1461,7 +1461,7 @@ expose its representation (like
14611461[ ` ErrorKind ` ] ( ../std/io/enum.ErrorKind.html ) ) or keep it hidden (like
14621462[ ` ParseIntError ` ] ( ../std/num/struct.ParseIntError.html ) ). Regardless
14631463of how you do it, it's usually good practice to at least provide some
1464- information about the error beyond just its ` String `
1464+ information about the error beyond its ` String `
14651465representation. But certainly, this will vary depending on use cases.
14661466
14671467At a minimum, you should probably implement the
@@ -1499,7 +1499,7 @@ that can go wrong!
14991499The data we'll be using comes from the [ Data Science
15001500Toolkit] [ 11 ] . I've prepared some data from it for this exercise. You
15011501can either grab the [ world population data] [ 12 ] (41MB gzip compressed,
1502- 145MB uncompressed) or just the [ US population data] [ 13 ] (2.2MB gzip
1502+ 145MB uncompressed) or only the [ US population data] [ 13 ] (2.2MB gzip
15031503compressed, 7.2MB uncompressed).
15041504
15051505Up until now, we've kept the code limited to Rust's standard library. For a real
@@ -1706,7 +1706,7 @@ compiler can no longer reason about its underlying type.
17061706
17071707[ Previously] ( #the-limits-of-combinators ) we started refactoring our code by
17081708changing the type of our function from ` T ` to ` Result<T, OurErrorType> ` . In
1709- this case, ` OurErrorType ` is just ` Box<Error> ` . But what's ` T ` ? And can we add
1709+ this case, ` OurErrorType ` is only ` Box<Error> ` . But what's ` T ` ? And can we add
17101710a return type to ` main ` ?
17111711
17121712The answer to the second question is no, we can't. That means we'll need to
@@ -1924,7 +1924,7 @@ parser out of
19241924But how can we use the same code over both types? There's actually a
19251925couple ways we could go about this. One way is to write ` search ` such
19261926that it is generic on some type parameter ` R ` that satisfies
1927- ` io::Read ` . Another way is to just use trait objects:
1927+ ` io::Read ` . Another way is to use trait objects:
19281928
19291929``` rust,ignore
19301930fn search<P: AsRef<Path>>
@@ -2081,7 +2081,7 @@ opts.optflag("q", "quiet", "Silences errors and warnings.");
20812081...
20822082```
20832083
2084- Now we just need to implement our “quiet” functionality. This requires us to
2084+ Now we only need to implement our “quiet” functionality. This requires us to
20852085tweak the case analysis in ` main ` :
20862086
20872087``` rust,ignore
@@ -2114,7 +2114,7 @@ handling in Rust. These are some good “rules of thumb." They are emphatically
21142114heuristics!
21152115
21162116* If you're writing short example code that would be overburdened by error
2117- handling, it's probably just fine to use ` unwrap ` (whether that's
2117+ handling, it's probably fine to use ` unwrap ` (whether that's
21182118 [ ` Result::unwrap ` ] ( ../std/result/enum.Result.html#method.unwrap ) ,
21192119 [ ` Option::unwrap ` ] ( ../std/option/enum.Option.html#method.unwrap )
21202120 or preferably
0 commit comments