This repository was archived by the owner on Aug 16, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Expand file tree Collapse file tree 3 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,17 @@ while let Some(cause) = fail.cause() {
59
59
}
60
60
```
61
61
62
+ For convenience an iterator is also provided:
63
+
64
+ ``` rust
65
+ // Assume err is a type that implements `Fail`
66
+ let mut fail : & Fail = err ;
67
+
68
+ for cause in fail . iter_causes () {
69
+ println! (" {}" , cause );
70
+ }
71
+ ```
72
+
62
73
## Backtraces
63
74
64
75
Errors can also generate a backtrace when they are constructed, helping you
Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ impl Error {
133
133
}
134
134
135
135
/// Returns a iterator over the causes of the `Error`, beginning with
136
- /// the failure returned by the `cause ` method and ending with the failure
136
+ /// the failure returned by the `as_fail ` method and ending with the failure
137
137
/// returned by `find_root_cause`.
138
138
pub fn iter_causes ( & self ) -> Causes {
139
139
self . as_fail ( ) . iter_causes ( )
Original file line number Diff line number Diff line change @@ -222,6 +222,10 @@ impl Fail {
222
222
223
223
/// Returns a iterator over the causes of this `Fail` with itself
224
224
/// as the first item and the `root_cause` as the final item.
225
+ ///
226
+ /// This means that `causes` also includes the fail itself which
227
+ /// means that it does *not* start with `cause`. To skip the outermost
228
+ /// fail use the `skip` method (`fail.causes().skip(1)`).
225
229
pub fn iter_causes ( & self ) -> Causes {
226
230
Causes { fail : Some ( self ) }
227
231
}
You can’t perform that action at this time.
0 commit comments