This repository was archived by the owner on Aug 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Expand file tree Collapse file tree 2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -47,15 +47,15 @@ more complex type like `Error` or your custom Error/ErrorKind.
4747
4848When you have a dependency which returns a different error type, often you will
4949be 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 )]
5454pub 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
Original file line number Diff line number Diff line change @@ -148,7 +148,7 @@ Backtrace type.
148148In contrast to ` backtrace ` , the cause cannot be determined by type name alone
149149because it could be any type which implements ` Fail ` . For this reason, if your
150150error has an underlying cause field, you need to annotate that field with
151- the ` #[cause] ` attribute.
151+ the ` #[fail( cause) ] ` attribute.
152152
153153This 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." )]
164164struct 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```
You can’t perform that action at this time.
0 commit comments