mirror of
				https://github.com/serde-rs/serde.git
				synced 2025-11-04 07:24:31 +00:00 
			
		
		
		
	Fix hand-written enum variant deserializations to allow u64 discriminant
Automatically generated enum variant deserializers allowed any integer type as the discriminant, but the hand-written ones for specific enum types such as Result or IpAddr only allowed types up to u32. This broke some non-human-readable deserializers for these enums, with deserializers that emit any integer type as a u64. Switch the visit_u32 methods to visit_u64 methods to allow discriminants to have any size up to a u64.
This commit is contained in:
		
							parent
							
								
									2e76f7013f
								
							
						
					
					
						commit
						45c45e87bf
					
				@ -1313,7 +1313,7 @@ macro_rules! variant_identifier {
 | 
				
			|||||||
                        formatter.write_str($expecting_message)
 | 
					                        formatter.write_str($expecting_message)
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
 | 
					                    fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
 | 
				
			||||||
                    where
 | 
					                    where
 | 
				
			||||||
                        E: Error,
 | 
					                        E: Error,
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -1321,7 +1321,7 @@ macro_rules! variant_identifier {
 | 
				
			|||||||
                            $(
 | 
					                            $(
 | 
				
			||||||
                                $index => Ok($name_kind :: $variant),
 | 
					                                $index => Ok($name_kind :: $variant),
 | 
				
			||||||
                            )*
 | 
					                            )*
 | 
				
			||||||
                            _ => Err(Error::invalid_value(Unexpected::Unsigned(value as u64), &self),),
 | 
					                            _ => Err(Error::invalid_value(Unexpected::Unsigned(value), &self),),
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -2326,7 +2326,7 @@ where
 | 
				
			|||||||
                        formatter.write_str("`Unbounded`, `Included` or `Excluded`")
 | 
					                        formatter.write_str("`Unbounded`, `Included` or `Excluded`")
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
 | 
					                    fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
 | 
				
			||||||
                    where
 | 
					                    where
 | 
				
			||||||
                        E: Error,
 | 
					                        E: Error,
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -2335,7 +2335,7 @@ where
 | 
				
			|||||||
                            1 => Ok(Field::Included),
 | 
					                            1 => Ok(Field::Included),
 | 
				
			||||||
                            2 => Ok(Field::Excluded),
 | 
					                            2 => Ok(Field::Excluded),
 | 
				
			||||||
                            _ => Err(Error::invalid_value(
 | 
					                            _ => Err(Error::invalid_value(
 | 
				
			||||||
                                Unexpected::Unsigned(value as u64),
 | 
					                                Unexpected::Unsigned(value),
 | 
				
			||||||
                                &self,
 | 
					                                &self,
 | 
				
			||||||
                            )),
 | 
					                            )),
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
@ -2492,7 +2492,7 @@ where
 | 
				
			|||||||
                        formatter.write_str("`Ok` or `Err`")
 | 
					                        formatter.write_str("`Ok` or `Err`")
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    fn visit_u32<E>(self, value: u32) -> Result<Self::Value, E>
 | 
					                    fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
 | 
				
			||||||
                    where
 | 
					                    where
 | 
				
			||||||
                        E: Error,
 | 
					                        E: Error,
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
@ -2500,7 +2500,7 @@ where
 | 
				
			|||||||
                            0 => Ok(Field::Ok),
 | 
					                            0 => Ok(Field::Ok),
 | 
				
			||||||
                            1 => Ok(Field::Err),
 | 
					                            1 => Ok(Field::Err),
 | 
				
			||||||
                            _ => Err(Error::invalid_value(
 | 
					                            _ => Err(Error::invalid_value(
 | 
				
			||||||
                                Unexpected::Unsigned(value as u64),
 | 
					                                Unexpected::Unsigned(value),
 | 
				
			||||||
                                &self,
 | 
					                                &self,
 | 
				
			||||||
                            )),
 | 
					                            )),
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user