mirror of
https://gitee.com/openharmony/third_party_rust_serde
synced 2024-11-23 06:50:23 +00:00
Merge pull request #1971 from arthurprs/untagged-enum-fix-pr
Allow floats to be deserialized from ints in untagged unions (part 2)
This commit is contained in:
commit
9a84622c56
@ -1741,6 +1741,25 @@ mod content {
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
}
|
||||
|
||||
fn deserialize_float<V>(self, visitor: V) -> Result<V::Value, E>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match *self.content {
|
||||
Content::F32(v) => visitor.visit_f32(v),
|
||||
Content::F64(v) => visitor.visit_f64(v),
|
||||
Content::U8(v) => visitor.visit_u8(v),
|
||||
Content::U16(v) => visitor.visit_u16(v),
|
||||
Content::U32(v) => visitor.visit_u32(v),
|
||||
Content::U64(v) => visitor.visit_u64(v),
|
||||
Content::I8(v) => visitor.visit_i8(v),
|
||||
Content::I16(v) => visitor.visit_i16(v),
|
||||
Content::I32(v) => visitor.visit_i32(v),
|
||||
Content::I64(v) => visitor.visit_i64(v),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_content_seq_ref<'a, 'de, V, E>(
|
||||
@ -1888,25 +1907,14 @@ mod content {
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match *self.content {
|
||||
Content::F32(v) => visitor.visit_f32(v),
|
||||
Content::F64(v) => visitor.visit_f64(v),
|
||||
Content::U64(v) => visitor.visit_u64(v),
|
||||
Content::I64(v) => visitor.visit_i64(v),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
self.deserialize_float(visitor)
|
||||
}
|
||||
|
||||
fn deserialize_f64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
where
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match *self.content {
|
||||
Content::F64(v) => visitor.visit_f64(v),
|
||||
Content::U64(v) => visitor.visit_u64(v),
|
||||
Content::I64(v) => visitor.visit_i64(v),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
self.deserialize_float(visitor)
|
||||
}
|
||||
|
||||
fn deserialize_char<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
||||
|
Loading…
Reference in New Issue
Block a user