Skip to content

Commit f2ea341

Browse files
authored
Merge pull request #1144 from lzutao/unused
Remove unused import and format with `rustfmt`
2 parents f931bec + 9f8d3a2 commit f2ea341

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/error/multiple_error_types/boxing_errors.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ via [`From`][from].
1111
```rust,editable
1212
use std::error;
1313
use std::fmt;
14-
use std::num::ParseIntError;
1514
1615
// Change the alias to `Box<error::Error>`.
1716
type Result<T> = std::result::Result<T, Box<error::Error>>;
@@ -38,15 +37,17 @@ impl error::Error for EmptyVec {
3837
3938
fn double_first(vec: Vec<&str>) -> Result<i32> {
4039
vec.first()
41-
.ok_or_else(|| EmptyVec.into()) // Converts to Box
42-
.and_then(|s| s.parse::<i32>()
43-
.map_err(|e| e.into()) // Converts to Box
44-
.map(|i| 2 * i))
40+
.ok_or_else(|| EmptyVec.into()) // Converts to Box
41+
.and_then(|s| {
42+
s.parse::<i32>()
43+
.map_err(|e| e.into()) // Converts to Box
44+
.map(|i| 2 * i)
45+
})
4546
}
4647
4748
fn print(result: Result<i32>) {
4849
match result {
49-
Ok(n) => println!("The first doubled is {}", n),
50+
Ok(n) => println!("The first doubled is {}", n),
5051
Err(e) => println!("Error: {}", e),
5152
}
5253
}

src/error/multiple_error_types/define_error_type.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ Rust allows us to define our own error types. In general, a "good" error type:
1818
```rust,editable
1919
use std::error;
2020
use std::fmt;
21-
use std::num::ParseIntError;
2221
2322
type Result<T> = std::result::Result<T, DoubleError>;
2423
25-
#[derive(Debug, Clone)]
2624
// Define our error types. These may be customized for our error handling cases.
2725
// Now we will be able to write our own errors, defer to an underlying error
2826
// implementation, or do something in between.
27+
#[derive(Debug, Clone)]
2928
struct DoubleError;
3029
3130
// Generation of an error is completely separate from how it is displayed.
@@ -53,17 +52,19 @@ impl error::Error for DoubleError {
5352
5453
fn double_first(vec: Vec<&str>) -> Result<i32> {
5554
vec.first()
56-
// Change the error to our new type.
57-
.ok_or(DoubleError)
58-
.and_then(|s| s.parse::<i32>()
59-
// Update to the new error type here also.
60-
.map_err(|_| DoubleError)
61-
.map(|i| 2 * i))
55+
// Change the error to our new type.
56+
.ok_or(DoubleError)
57+
.and_then(|s| {
58+
s.parse::<i32>()
59+
// Update to the new error type here also.
60+
.map_err(|_| DoubleError)
61+
.map(|i| 2 * i)
62+
})
6263
}
6364
6465
fn print(result: Result<i32>) {
6566
match result {
66-
Ok(n) => println!("The first doubled is {}", n),
67+
Ok(n) => println!("The first doubled is {}", n),
6768
Err(e) => println!("Error: {}", e),
6869
}
6970
}

0 commit comments

Comments
 (0)