diff options
author | Kornel <kornel@geekhood.net> | 2018-08-05 23:25:06 +0100 |
---|---|---|
committer | Kornel <kornel@geekhood.net> | 2018-08-05 23:25:06 +0100 |
commit | de6b59fb12c5ad51d94831893536f09fcd29ee8b (patch) | |
tree | ebeb42a4963d5ec2b1cef18e9642e2f29bd61ad1 | |
parent | 55a11b89550fb280e3f889cc1b8c9073de6fb937 (diff) | |
download | milf-rs-de6b59fb12c5ad51d94831893536f09fcd29ee8b.tar.gz milf-rs-de6b59fb12c5ad51d94831893536f09fcd29ee8b.zip |
Support deserializing from other integer types
-rw-r--r-- | src/value.rs | 16 |
1 files changed, 16 insertions, 0 deletions
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<E: de::Error>(self, value: u64) -> Result<Value, E> { + 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<E>(self, value: u32) -> Result<Value, E> { + Ok(Value::Integer(value.into())) + } + + fn visit_i32<E>(self, value: i32) -> Result<Value, E> { + Ok(Value::Integer(value.into())) + } + fn visit_f64<E>(self, value: f64) -> Result<Value, E> { Ok(Value::Float(value)) } |