9
9
// except according to those terms.
10
10
11
11
//! Traits for working with Errors.
12
- //!
13
- //! # The `Error` trait
14
- //!
15
- //! `Error` is a trait representing the basic expectations for error values,
16
- //! i.e. values of type `E` in [`Result<T, E>`]. At a minimum, errors must provide
17
- //! a description, but they may optionally provide additional detail (via
18
- //! [`Display`]) and cause chain information:
19
- //!
20
- //! ```
21
- //! use std::fmt::Display;
22
- //!
23
- //! trait Error: Display {
24
- //! fn description(&self) -> &str;
25
- //!
26
- //! fn cause(&self) -> Option<&Error> { None }
27
- //! }
28
- //! ```
29
- //!
30
- //! The [`cause`] method is generally used when errors cross "abstraction
31
- //! boundaries", i.e. when a one module must report an error that is "caused"
32
- //! by an error from a lower-level module. This setup makes it possible for the
33
- //! high-level module to provide its own errors that do not commit to any
34
- //! particular implementation, but also reveal some of its implementation for
35
- //! debugging via [`cause`] chains.
36
- //!
37
- //! [`Result<T, E>`]: ../result/enum.Result.html
38
- //! [`Display`]: ../fmt/trait.Display.html
39
- //! [`cause`]: trait.Error.html#method.cause
40
12
41
13
#![ stable( feature = "rust1" , since = "1.0.0" ) ]
42
14
@@ -63,7 +35,31 @@ use num;
63
35
use str;
64
36
use string;
65
37
66
- /// Base functionality for all errors in Rust.
38
+ /// `Error` is a trait representing the basic expectations for error values,
39
+ /// i.e. values of type `E` in [`Result<T, E>`]. At a minimum, errors must provide
40
+ /// a description, but they may optionally provide additional detail (via
41
+ /// [`Display`]) and cause chain information:
42
+ ///
43
+ /// ```
44
+ /// use std::fmt::Display;
45
+ ///
46
+ /// trait Error: Display {
47
+ /// fn description(&self) -> &str;
48
+ ///
49
+ /// fn cause(&self) -> Option<&Error> { None }
50
+ /// }
51
+ /// ```
52
+ ///
53
+ /// The [`cause`] method is generally used when errors cross "abstraction
54
+ /// boundaries", i.e. when a one module must report an error that is "caused"
55
+ /// by an error from a lower-level module. This setup makes it possible for the
56
+ /// high-level module to provide its own errors that do not commit to any
57
+ /// particular implementation, but also reveal some of its implementation for
58
+ /// debugging via [`cause`] chains.
59
+ ///
60
+ /// [`Result<T, E>`]: ../result/enum.Result.html
61
+ /// [`Display`]: ../fmt/trait.Display.html
62
+ /// [`cause`]: trait.Error.html#method.cause
67
63
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
68
64
pub trait Error : Debug + Display {
69
65
/// A short description of the error.
0 commit comments