@@ -1829,7 +1829,7 @@ use std::error::Error;
1829
1829
1830
1830
fn search<P: AsRef<Path>>
1831
1831
(file_path: P, city: &str)
1832
- -> Result<Vec<PopulationCount>, Box<Error+Send+Sync >> {
1832
+ -> Result<Vec<PopulationCount>, Box<Error>> {
1833
1833
let mut found = vec![];
1834
1834
let file = try!(File::open(file_path));
1835
1835
let mut rdr = csv::Reader::from_reader(file);
@@ -1858,20 +1858,17 @@ Instead of `x.unwrap()`, we now have `try!(x)`. Since our function returns a
1858
1858
` Result<T, E> ` , the ` try! ` macro will return early from the function if an
1859
1859
error occurs.
1860
1860
1861
- There is one big gotcha in this code: we used ` Box<Error + Send + Sync> `
1862
- instead of ` Box<Error> ` . We did this so we could convert a plain string to an
1863
- error type. We need these extra bounds so that we can use the
1864
- [ corresponding ` From `
1865
- impls] ( ../std/convert/trait.From.html ) :
1861
+ At the end of ` search ` we also convert a plain string to an error type
1862
+ by using the [ corresponding ` From ` impls] ( ../std/convert/trait.From.html ) :
1866
1863
1867
1864
``` rust,ignore
1868
1865
// We are making use of this impl in the code above, since we call `From::from`
1869
1866
// on a `&'static str`.
1870
- impl<'a, 'b > From<&'b str> for Box<Error + Send + Sync + 'a >
1867
+ impl<'a> From<&'a str> for Box<Error>
1871
1868
1872
1869
// But this is also useful when you need to allocate a new string for an
1873
1870
// error message, usually with `format!`.
1874
- impl From<String> for Box<Error + Send + Sync >
1871
+ impl From<String> for Box<Error>
1875
1872
```
1876
1873
1877
1874
Since ` search ` now returns a ` Result<T, E> ` , ` main ` should use case analysis
@@ -1964,7 +1961,7 @@ use std::io;
1964
1961
1965
1962
fn search<P: AsRef<Path>>
1966
1963
(file_path: &Option<P>, city: &str)
1967
- -> Result<Vec<PopulationCount>, Box<Error+Send+Sync >> {
1964
+ -> Result<Vec<PopulationCount>, Box<Error>> {
1968
1965
let mut found = vec![];
1969
1966
let input: Box<io::Read> = match *file_path {
1970
1967
None => Box::new(io::stdin()),
@@ -2175,9 +2172,8 @@ heuristics!
2175
2172
` unwrap ` . Be warned: if it winds up in someone else's hands, don't be
2176
2173
surprised if they are agitated by poor error messages!
2177
2174
* If you're writing a quick 'n' dirty program and feel ashamed about panicking
2178
- anyway, then use either a ` String ` or a ` Box<Error + Send + Sync> ` for your
2179
- error type (the ` Box<Error + Send + Sync> ` type is because of the
2180
- [ available ` From ` impls] ( ../std/convert/trait.From.html ) ).
2175
+ anyway, then use either a ` String ` or a ` Box<Error> ` for your
2176
+ error type.
2181
2177
* Otherwise, in a program, define your own error types with appropriate
2182
2178
[ ` From ` ] ( ../std/convert/trait.From.html )
2183
2179
and
0 commit comments