@@ -74,18 +74,19 @@ pub trait ValueTypeOptional:
74
74
{
75
75
}
76
76
77
- impl < T , C > ValueType for Option < T >
77
+ impl < T , C , E > ValueType for Option < T >
78
78
where
79
79
T : for < ' a > FromValue < ' a , Checker = C > + ValueTypeOptional + StaticType + ' static ,
80
- C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError > ,
80
+ C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError < E > > ,
81
+ E : error:: Error ,
81
82
{
82
83
type Type = T :: Type ;
83
84
}
84
85
85
86
// rustdoc-stripper-ignore-next
86
87
/// Trait for `Value` type checkers.
87
88
pub unsafe trait ValueTypeChecker {
88
- type Error : std :: error:: Error + Send + Sized + ' static ;
89
+ type Error : error:: Error + Send + Sized + ' static ;
89
90
90
91
fn check ( value : & Value ) -> Result < ( ) , Self :: Error > ;
91
92
}
@@ -207,40 +208,34 @@ impl From<Infallible> for InvalidCharError {
207
208
/// An error returned from the [`get`](struct.Value.html#method.get)
208
209
/// function on a [`Value`](struct.Value.html) for optional types.
209
210
#[ derive( Clone , PartialEq , Eq , Debug ) ]
210
- pub enum ValueTypeMismatchOrNoneError {
211
- WrongValueType ( ValueTypeMismatchError ) ,
211
+ pub enum ValueTypeMismatchOrNoneError < E : error :: Error > {
212
+ WrongValueType ( E ) ,
212
213
UnexpectedNone ,
213
214
}
214
215
215
- impl fmt:: Display for ValueTypeMismatchOrNoneError {
216
+ impl < E : error :: Error > fmt:: Display for ValueTypeMismatchOrNoneError < E > {
216
217
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
217
218
match self {
218
- Self :: WrongValueType ( err) => err . fmt ( f) ,
219
+ Self :: WrongValueType ( err) => < E as fmt:: Display > :: fmt ( err , f) ,
219
220
Self :: UnexpectedNone => write ! ( f, "Unexpected None" , ) ,
220
221
}
221
222
}
222
223
}
223
224
224
- impl error:: Error for ValueTypeMismatchOrNoneError { }
225
+ impl < E : error:: Error > error :: Error for ValueTypeMismatchOrNoneError < E > { }
225
226
226
- impl From < ValueTypeMismatchError > for ValueTypeMismatchOrNoneError {
227
- fn from ( err : ValueTypeMismatchError ) -> Self {
227
+ impl < E : error :: Error > From < E > for ValueTypeMismatchOrNoneError < E > {
228
+ fn from ( err : E ) -> Self {
228
229
Self :: WrongValueType ( err)
229
230
}
230
231
}
231
232
232
- impl From < Infallible > for ValueTypeMismatchOrNoneError {
233
- fn from ( e : Infallible ) -> Self {
234
- match e { }
235
- }
236
- }
237
-
238
233
// rustdoc-stripper-ignore-next
239
234
/// Generic `Value` type checker for optional types.
240
235
pub struct GenericValueTypeOrNoneChecker < T > ( std:: marker:: PhantomData < T > ) ;
241
236
242
237
unsafe impl < T : StaticType > ValueTypeChecker for GenericValueTypeOrNoneChecker < T > {
243
- type Error = ValueTypeMismatchOrNoneError ;
238
+ type Error = ValueTypeMismatchOrNoneError < ValueTypeMismatchError > ;
244
239
245
240
fn check ( value : & Value ) -> Result < ( ) , Self :: Error > {
246
241
GenericValueTypeChecker :: < T > :: check ( value) ?;
@@ -281,30 +276,33 @@ pub unsafe trait FromValue<'a>: Sized {
281
276
/// This trait is auto-implemented for the appropriate types and is sealed.
282
277
pub trait FromValueOptional < ' a > : private:: FromValueOptionalSealed < ' a > { }
283
278
284
- impl < ' a , T , C > FromValueOptional < ' a > for T
279
+ impl < ' a , T , C , E > FromValueOptional < ' a > for T
285
280
where
286
281
T : FromValue < ' a , Checker = C > ,
287
- C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError > ,
282
+ C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError < E > > ,
283
+ E : error:: Error ,
288
284
{
289
285
}
290
286
291
287
mod private {
292
288
pub trait FromValueOptionalSealed < ' a > { }
293
289
294
- impl < ' a , T , C > FromValueOptionalSealed < ' a > for T
290
+ impl < ' a , T , C , E > FromValueOptionalSealed < ' a > for T
295
291
where
296
292
T : super :: FromValue < ' a , Checker = C > ,
297
- C : super :: ValueTypeChecker < Error = super :: ValueTypeMismatchOrNoneError > ,
293
+ C : super :: ValueTypeChecker < Error = super :: ValueTypeMismatchOrNoneError < E > > ,
294
+ E : super :: error:: Error ,
298
295
{
299
296
}
300
297
}
301
298
302
299
// rustdoc-stripper-ignore-next
303
300
/// Blanket implementation for all optional types.
304
- unsafe impl < ' a , T , C > FromValue < ' a > for Option < T >
301
+ unsafe impl < ' a , T , C , E > FromValue < ' a > for Option < T >
305
302
where
306
303
T : FromValue < ' a , Checker = C > + StaticType ,
307
- C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError > ,
304
+ C : ValueTypeChecker < Error = ValueTypeMismatchOrNoneError < E > > ,
305
+ E : error:: Error ,
308
306
{
309
307
type Checker = GenericValueTypeChecker < T > ;
310
308
0 commit comments