diff options
author | Alex Crichton <alex@alexcrichton.com> | 2018-08-06 10:17:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-06 10:17:30 -0500 |
commit | 8181a7e645064426b43891b0f4c7fa86c2a2d154 (patch) | |
tree | b08ac7fbe55ab74731c838f90dc6fd36a6f14f58 /src | |
parent | 7c1da18505c5773cfb3653790976ab18837e9feb (diff) | |
parent | bc726bb0426dc4a54d6b9f4281bbd98b826bc625 (diff) | |
download | milf-rs-8181a7e645064426b43891b0f4c7fa86c2a2d154.tar.gz milf-rs-8181a7e645064426b43891b0f4c7fa86c2a2d154.zip |
Merge pull request #255 from kornelski/master
Support deserializing from other integer types
Diffstat (limited to 'src')
-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)) } |