@@ -10,7 +10,9 @@ use serde::ser;
10
10
11
11
/// This type represents all possible errors that can occur when serializing or
12
12
/// deserializing JSON data.
13
- pub struct Error ( Box < ErrorImpl > ) ;
13
+ pub struct Error {
14
+ err : Box < ErrorImpl > ,
15
+ }
14
16
15
17
/// Alias for a `Result` with the error type `serde_json::Error`.
16
18
pub type Result < T > = result:: Result < T , Error > ;
@@ -89,15 +91,17 @@ impl Error {
89
91
// Not public API. Should be pub(crate).
90
92
#[ doc( hidden) ]
91
93
pub fn syntax ( code : ErrorCode , line : usize , col : usize ) -> Self {
92
- Error ( Box :: new ( ErrorImpl :: Syntax ( code, line, col) ) )
94
+ Error {
95
+ err : Box :: new ( ErrorImpl :: Syntax ( code, line, col) ) ,
96
+ }
93
97
}
94
98
95
99
// Not public API. Should be pub(crate).
96
100
#[ doc( hidden) ]
97
101
pub fn fix_position < F > ( self , f : F ) -> Self
98
102
where F : FnOnce ( ErrorCode ) -> Error
99
103
{
100
- if let ErrorImpl :: Syntax ( code, 0 , 0 ) = * self . 0 {
104
+ if let ErrorImpl :: Syntax ( code, 0 , 0 ) = * self . err {
101
105
f ( code)
102
106
} else {
103
107
self
@@ -169,14 +173,14 @@ impl Display for ErrorCode {
169
173
170
174
impl error:: Error for Error {
171
175
fn description ( & self ) -> & str {
172
- match * self . 0 {
176
+ match * self . err {
173
177
ErrorImpl :: Syntax ( ..) => "syntax error" ,
174
178
ErrorImpl :: Io ( ref error) => error:: Error :: description ( error) ,
175
179
}
176
180
}
177
181
178
182
fn cause ( & self ) -> Option < & error:: Error > {
179
- match * self . 0 {
183
+ match * self . err {
180
184
ErrorImpl :: Io ( ref error) => Some ( error) ,
181
185
_ => None ,
182
186
}
@@ -185,7 +189,7 @@ impl error::Error for Error {
185
189
186
190
impl Display for Error {
187
191
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
188
- match * self . 0 {
192
+ match * self . err {
189
193
ErrorImpl :: Syntax ( ref code, line, col) => {
190
194
if line == 0 && col == 0 {
191
195
write ! ( fmt, "{}" , code)
@@ -202,7 +206,7 @@ impl Display for Error {
202
206
// end up seeing this representation because it is what unwrap() shows.
203
207
impl Debug for Error {
204
208
fn fmt ( & self , formatter : & mut fmt:: Formatter ) -> fmt:: Result {
205
- match * self . 0 {
209
+ match * self . err {
206
210
ErrorImpl :: Syntax ( ref code, ref line, ref col) => {
207
211
formatter. debug_tuple ( "Syntax" )
208
212
. field ( code)
@@ -221,30 +225,40 @@ impl Debug for Error {
221
225
222
226
impl From < ErrorImpl > for Error {
223
227
fn from ( error : ErrorImpl ) -> Error {
224
- Error ( Box :: new ( error) )
228
+ Error {
229
+ err : Box :: new ( error) ,
230
+ }
225
231
}
226
232
}
227
233
228
234
impl From < io:: Error > for Error {
229
235
fn from ( error : io:: Error ) -> Error {
230
- Error ( Box :: new ( ErrorImpl :: Io ( error) ) )
236
+ Error {
237
+ err : Box :: new ( ErrorImpl :: Io ( error) ) ,
238
+ }
231
239
}
232
240
}
233
241
234
242
impl From < de:: value:: Error > for Error {
235
243
fn from ( error : de:: value:: Error ) -> Error {
236
- Error ( Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( error. to_string ( ) ) , 0 , 0 ) ) )
244
+ Error {
245
+ err : Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( error. to_string ( ) ) , 0 , 0 ) ) ,
246
+ }
237
247
}
238
248
}
239
249
240
250
impl de:: Error for Error {
241
251
fn custom < T : Display > ( msg : T ) -> Error {
242
- Error ( Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( msg. to_string ( ) ) , 0 , 0 ) ) )
252
+ Error {
253
+ err : Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( msg. to_string ( ) ) , 0 , 0 ) ) ,
254
+ }
243
255
}
244
256
}
245
257
246
258
impl ser:: Error for Error {
247
259
fn custom < T : Display > ( msg : T ) -> Error {
248
- Error ( Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( msg. to_string ( ) ) , 0 , 0 ) ) )
260
+ Error {
261
+ err : Box :: new ( ErrorImpl :: Syntax ( ErrorCode :: Message ( msg. to_string ( ) ) , 0 , 0 ) ) ,
262
+ }
249
263
}
250
264
}
0 commit comments