Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 82e5774

Browse files
committed
Use fail(cause) in the docs
1 parent 8681327 commit 82e5774

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

book/src/custom-fail.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ more complex type like `Error` or your custom Error/ErrorKind.
4747

4848
When you have a dependency which returns a different error type, often you will
4949
be inclined to add it as a variant on your own error type. When you do that,
50-
you should tag the underlying error as the `#[cause]` of your error:
50+
you should tag the underlying error as the `#[fail(cause)]` of your error:
5151

5252
```rust
5353
#[derive(Fail, Debug)]
5454
pub enum MyError {
5555
#[fail(display = "Input was invalid UTF-8 at index {}", _0)]
5656
Utf8Error(usize),
5757
#[fail(display = "{}", _0)]
58-
Io(#[cause] io::Error),
58+
Io(#[fail(cause)] io::Error),
5959
}
6060
```
6161

book/src/derive-fail.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Backtrace type.
148148
In contrast to `backtrace`, the cause cannot be determined by type name alone
149149
because it could be any type which implements `Fail`. For this reason, if your
150150
error has an underlying cause field, you need to annotate that field with
151-
the `#[cause]` attribute.
151+
the `#[fail(cause)]` attribute.
152152

153153
This can be used in fields of enums as well as structs.
154154

@@ -162,7 +162,7 @@ use std::io;
162162
#[derive(Fail, Debug)]
163163
#[fail(display = "An error occurred.")]
164164
struct MyError {
165-
#[cause] io_error: io::Error,
165+
#[fail(cause)] io_error: io::Error,
166166
}
167167

168168
/// MyEnumError::cause will return a reference only if it is Variant2,
@@ -172,6 +172,6 @@ enum MyEnumError {
172172
#[fail(display = "An error occurred.")]
173173
Variant1,
174174
#[fail(display = "A different error occurred.")]
175-
Variant2(#[cause] io::Error),
175+
Variant2(#[fail(cause)] io::Error),
176176
}
177177
```

0 commit comments

Comments
 (0)