From de6b59fb12c5ad51d94831893536f09fcd29ee8b Mon Sep 17 00:00:00 2001 From: Kornel Date: Sun, 5 Aug 2018 23:25:06 +0100 Subject: Support deserializing from other integer types --- src/value.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/value.rs b/src/value.rs index 21a8205..64f4555 100644 --- a/src/value.rs +++ b/src/value.rs @@ -423,6 +423,22 @@ impl<'de> de::Deserialize<'de> for Value { Ok(Value::Integer(value)) } + fn visit_u64(self, value: u64) -> Result { + if value <= i64::max_value() as u64 { + Ok(Value::Integer(value as i64)) + } else { + Err(de::Error::custom("u64 value was too large")) + } + } + + fn visit_u32(self, value: u32) -> Result { + Ok(Value::Integer(value.into())) + } + + fn visit_i32(self, value: i32) -> Result { + Ok(Value::Integer(value.into())) + } + fn visit_f64(self, value: f64) -> Result { Ok(Value::Float(value)) } -- cgit v1.2.3