@@ -135,19 +135,6 @@ impl ReflectDeserializerProcessor for () {
135135 }
136136}
137137
138- impl < T : ReflectDeserializerProcessor + ?Sized > ReflectDeserializerProcessor for & mut T {
139- fn try_deserialize < ' de , D > (
140- & mut self ,
141- registration : & TypeRegistration ,
142- deserializer : D ,
143- ) -> Result < Result < Box < dyn PartialReflect > , D > , D :: Error >
144- where
145- D : serde:: Deserializer < ' de > ,
146- {
147- ( * self ) . try_deserialize ( registration, deserializer)
148- }
149- }
150-
151138/// A general purpose deserializer for reflected types.
152139///
153140/// This is the deserializer counterpart to [`ReflectSerializer`].
@@ -234,20 +221,20 @@ impl<T: ReflectDeserializerProcessor + ?Sized> ReflectDeserializerProcessor for
234221/// [`new_with_processor`]: Self::new_with_processor
235222pub struct ReflectDeserializer < ' a , P > {
236223 registry : & ' a TypeRegistry ,
237- processor : P ,
224+ processor : Option < & ' a mut P > ,
238225}
239226
240227impl < ' a > ReflectDeserializer < ' a , ( ) > {
241228 /// Creates a deserializer with no processor.
242229 ///
243230 /// If you want to add custom logic for deserializing certain types, use
244- /// [`new_with_processor `].
231+ /// [`with_processor `].
245232 ///
246- /// [`new_with_processor `]: Self::new_with_processor
233+ /// [`with_processor `]: Self::with_processor
247234 pub fn new ( registry : & ' a TypeRegistry ) -> Self {
248235 Self {
249236 registry,
250- processor : ( ) ,
237+ processor : None ,
251238 }
252239 }
253240}
@@ -259,10 +246,10 @@ impl<'a, P: ReflectDeserializerProcessor> ReflectDeserializer<'a, P> {
259246 /// [`new`].
260247 ///
261248 /// [`new`]: Self::new
262- pub fn new_with_processor ( registry : & ' a TypeRegistry , processor : P ) -> Self {
249+ pub fn with_processor ( registry : & ' a TypeRegistry , processor : & ' a mut P ) -> Self {
263250 Self {
264251 registry,
265- processor,
252+ processor : Some ( processor ) ,
266253 }
267254 }
268255}
@@ -276,11 +263,11 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser
276263 {
277264 struct UntypedReflectDeserializerVisitor < ' a , P > {
278265 registry : & ' a TypeRegistry ,
279- processor : P ,
266+ processor : Option < & ' a mut P > ,
280267 }
281268
282- impl < ' a , ' de , P : ReflectDeserializerProcessor > Visitor < ' de >
283- for UntypedReflectDeserializerVisitor < ' a , P >
269+ impl < ' de , P : ReflectDeserializerProcessor > Visitor < ' de >
270+ for UntypedReflectDeserializerVisitor < ' _ , P >
284271 {
285272 type Value = Box < dyn PartialReflect > ;
286273
@@ -289,7 +276,7 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser
289276 . write_str ( "map containing `type` and `value` entries for the reflected value" )
290277 }
291278
292- fn visit_map < A > ( self , mut map : A ) -> Result < Self :: Value , A :: Error >
279+ fn visit_map < A > ( mut self , mut map : A ) -> Result < Self :: Value , A :: Error >
293280 where
294281 A : MapAccess < ' de > ,
295282 {
@@ -300,7 +287,7 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser
300287 let value = map. next_value_seed ( TypedReflectDeserializer {
301288 registration,
302289 registry : self . registry ,
303- processor : self . processor ,
290+ processor : self . processor . as_deref_mut ( ) ,
304291 } ) ?;
305292
306293 if map. next_key :: < IgnoredAny > ( ) ?. is_some ( ) {
@@ -402,24 +389,24 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de> for ReflectDeser
402389pub struct TypedReflectDeserializer < ' a , P > {
403390 registration : & ' a TypeRegistration ,
404391 registry : & ' a TypeRegistry ,
405- processor : P ,
392+ processor : Option < & ' a mut P > ,
406393}
407394
408395impl < ' a > TypedReflectDeserializer < ' a , ( ) > {
409396 /// Creates a typed deserializer with no processor.
410397 ///
411398 /// If you want to add custom logic for deserializing certain types, use
412- /// [`new_with_processor `].
399+ /// [`with_processor `].
413400 ///
414- /// [`new_with_processor `]: Self::new_with_processor
401+ /// [`with_processor `]: Self::with_processor
415402 pub fn new ( registration : & ' a TypeRegistration , registry : & ' a TypeRegistry ) -> Self {
416403 #[ cfg( feature = "debug_stack" ) ]
417404 TYPE_INFO_STACK . set ( crate :: type_info_stack:: TypeInfoStack :: new ( ) ) ;
418405
419406 Self {
420407 registration,
421408 registry,
422- processor : ( ) ,
409+ processor : None ,
423410 }
424411 }
425412}
@@ -431,26 +418,26 @@ impl<'a, P: ReflectDeserializerProcessor> TypedReflectDeserializer<'a, P> {
431418 /// [`new`].
432419 ///
433420 /// [`new`]: Self::new
434- pub fn new_with_processor (
421+ pub fn with_processor (
435422 registration : & ' a TypeRegistration ,
436423 registry : & ' a TypeRegistry ,
437- processor : P ,
424+ processor : & ' a mut P ,
438425 ) -> Self {
439426 #[ cfg( feature = "debug_stack" ) ]
440427 TYPE_INFO_STACK . set ( crate :: type_info_stack:: TypeInfoStack :: new ( ) ) ;
441428
442429 Self {
443430 registration,
444431 registry,
445- processor,
432+ processor : Some ( processor ) ,
446433 }
447434 }
448435
449436 /// An internal constructor for creating a deserializer without resetting the type info stack.
450437 pub ( super ) fn new_internal (
451438 registration : & ' a TypeRegistration ,
452439 registry : & ' a TypeRegistry ,
453- processor : P ,
440+ processor : Option < & ' a mut P > ,
454441 ) -> Self {
455442 Self {
456443 registration,
@@ -472,17 +459,18 @@ impl<'de, P: ReflectDeserializerProcessor> DeserializeSeed<'de>
472459 let deserialize_internal = || -> Result < Self :: Value , D :: Error > {
473460 // First, check if our processor wants to deserialize this type
474461 // This takes priority over any other deserialization operations
475- let deserializer = match self
476- . processor
477- . try_deserialize ( self . registration , deserializer )
478- {
479- Ok ( Ok ( value ) ) => {
480- return Ok ( value ) ;
481- }
482- Err ( err ) => {
483- return Err ( make_custom_error ( err ) ) ;
462+ let deserializer = if let Some ( processor ) = self . processor . as_deref_mut ( ) {
463+ match processor. try_deserialize ( self . registration , deserializer ) {
464+ Ok ( Ok ( value ) ) => {
465+ return Ok ( value ) ;
466+ }
467+ Err ( err ) => {
468+ return Err ( make_custom_error ( err ) ) ;
469+ }
470+ Ok ( Err ( deserializer ) ) => deserializer ,
484471 }
485- Ok ( Err ( deserializer) ) => deserializer,
472+ } else {
473+ deserializer
486474 } ;
487475
488476 let type_path = self . registration . type_info ( ) . type_path ( ) ;
0 commit comments