@@ -3,28 +3,14 @@ use core::{fmt, result};
33pub ( super ) type Result < T > = result:: Result < T , Error > ;
44
55/// A minimal backfill of the [`std::io::Error`] for `no_std` environments.
6- pub struct Error {
7- repr : Repr ,
8- }
9-
10- impl core:: error:: Error for Error { }
11-
12- impl fmt:: Debug for Error {
13- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
14- fmt:: Debug :: fmt ( & self . repr , f)
15- }
16- }
17-
18- enum Repr {
19- Custom ( Custom ) ,
20- }
21-
226#[ derive( Debug ) ]
23- struct Custom {
7+ pub struct Error {
248 kind : ErrorKind ,
259 error : & ' static str ,
2610}
2711
12+ impl core:: error:: Error for Error { }
13+
2814/// A list specifying general categories of I/O error.
2915///
3016/// This list is intended to grow over time and it is not recommended to
@@ -66,35 +52,17 @@ impl Error {
6652 /// originate from the OS itself. The `error` argument is an arbitrary
6753 /// payload which will be contained in this [`Error`].
6854 pub ( super ) fn new ( kind : ErrorKind , error : & ' static str ) -> Error {
69- Self :: _new ( kind, error)
70- }
71-
72- fn _new ( kind : ErrorKind , error : & ' static str ) -> Error {
73- Error {
74- repr : Repr :: Custom ( Custom { kind, error } ) ,
75- }
55+ Error { kind, error }
7656 }
7757
7858 /// Returns the corresponding [`ErrorKind`] for this error.
7959 pub ( super ) fn kind ( & self ) -> ErrorKind {
80- match self . repr {
81- Repr :: Custom ( ref c) => c. kind ,
82- }
83- }
84- }
85-
86- impl fmt:: Debug for Repr {
87- fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
88- match * self {
89- Repr :: Custom ( ref c) => fmt:: Debug :: fmt ( & c, fmt) ,
90- }
60+ self . kind
9161 }
9262}
9363
9464impl fmt:: Display for Error {
9565 fn fmt ( & self , fmt : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
96- match self . repr {
97- Repr :: Custom ( ref c) => c. error . fmt ( fmt) ,
98- }
66+ self . error . fmt ( fmt)
9967 }
10068}
0 commit comments