summaryrefslogtreecommitdiff
path: root/serde_dhall/src
diff options
context:
space:
mode:
authorNadrieril2020-05-10 19:32:34 +0100
committerNadrieril2020-10-28 20:18:17 +0000
commit9e3f68fc54babf24133cf66ae6be7d069ba2c271 (patch)
treeac3f0782fb90c8f6b03b3d29d1032d06d637e4ee /serde_dhall/src
parent2b4ba42b7f0a44893f17548f069cec1e60819aa4 (diff)
Prefer u64/i64 to usize/isize
Diffstat (limited to 'serde_dhall/src')
-rw-r--r--serde_dhall/src/deserialize.rs32
-rw-r--r--serde_dhall/src/lib.rs4
-rw-r--r--serde_dhall/src/options.rs6
3 files changed, 9 insertions, 33 deletions
diff --git a/serde_dhall/src/deserialize.rs b/serde_dhall/src/deserialize.rs
index 1206033..12b4703 100644
--- a/serde_dhall/src/deserialize.rs
+++ b/serde_dhall/src/deserialize.rs
@@ -1,6 +1,5 @@
use std::borrow::Cow;
use std::collections::BTreeMap;
-use std::convert::TryInto as _;
use std::fmt;
use serde::de::value::{
@@ -124,31 +123,14 @@ impl<'de: 'a, 'a> serde::Deserializer<'de> for Deserializer<'a> {
where
V: serde::de::Visitor<'de>,
{
- use std::convert::TryInto;
use NumKind::*;
use SimpleValue::*;
let val = |x| Deserializer(Cow::Borrowed(x));
match self.0.as_ref() {
Num(Bool(x)) => visitor.visit_bool(*x),
- Num(Natural(x)) => {
- if let Ok(x64) = (*x).try_into() {
- visitor.visit_u64(x64)
- } else if let Ok(x32) = (*x).try_into() {
- visitor.visit_u32(x32)
- } else {
- unimplemented!()
- }
- }
- Num(Integer(x)) => {
- if let Ok(x64) = (*x).try_into() {
- visitor.visit_i64(x64)
- } else if let Ok(x32) = (*x).try_into() {
- visitor.visit_i32(x32)
- } else {
- unimplemented!()
- }
- }
+ Num(Natural(x)) => visitor.visit_u64(*x),
+ Num(Integer(x)) => visitor.visit_i64(*x),
Num(Double(x)) => visitor.visit_f64((*x).into()),
Text(x) => visitor.visit_str(x),
List(xs) => {
@@ -210,17 +192,11 @@ impl<'de> serde::de::Visitor<'de> for SimpleValueVisitor {
}
fn visit_i64<E>(self, value: i64) -> Result<SimpleValue, E> {
- // TODO: use `i64` instead of `isize` in `NumKind`.
- Ok(SimpleValue::Num(NumKind::Integer(
- value.try_into().unwrap(),
- )))
+ Ok(SimpleValue::Num(NumKind::Integer(value)))
}
fn visit_u64<E>(self, value: u64) -> Result<SimpleValue, E> {
- // TODO: use `u64` instead of `usize` in `NumKind`.
- Ok(SimpleValue::Num(NumKind::Natural(
- value.try_into().unwrap(),
- )))
+ Ok(SimpleValue::Num(NumKind::Natural(value)))
}
fn visit_f64<E>(self, value: f64) -> Result<SimpleValue, E> {
diff --git a/serde_dhall/src/lib.rs b/serde_dhall/src/lib.rs
index cf9343a..8291f74 100644
--- a/serde_dhall/src/lib.rs
+++ b/serde_dhall/src/lib.rs
@@ -30,7 +30,7 @@
//! let data = "{ x = 1, y = 1 + 1 } : { x: Natural, y: Natural }";
//!
//! // Deserialize it to a Rust type.
-//! let deserialized_map: HashMap<String, usize> = serde_dhall::from_str(data).parse()?;
+//! let deserialized_map: HashMap<String, u64> = serde_dhall::from_str(data).parse()?;
//!
//! let mut expected_map = HashMap::new();
//! expected_map.insert("x".to_string(), 1);
@@ -140,7 +140,7 @@
//! // the data matches the provided type.
//! let deserialized_map = serde_dhall::from_str(point_data)
//! .type_annotation(&point_type)
-//! .parse::<HashMap<String, usize>>()?;
+//! .parse::<HashMap<String, u64>>()?;
//!
//! let mut expected_map = HashMap::new();
//! expected_map.insert("x".to_string(), 1);
diff --git a/serde_dhall/src/options.rs b/serde_dhall/src/options.rs
index 76b1c5b..7b27114 100644
--- a/serde_dhall/src/options.rs
+++ b/serde_dhall/src/options.rs
@@ -76,7 +76,7 @@ impl<T: StaticType> HasAnnot<StaticAnnot> for T {
/// let ty = from_str("{ x: Natural, y: Natural }").parse()?;
/// let data = from_file("foo.dhall")
/// .type_annotation(&ty)
-/// .parse::<HashMap<String, usize>>()?;
+/// .parse::<HashMap<String, u64>>()?;
/// # Ok(())
/// # }
/// ```
@@ -130,7 +130,7 @@ impl<'a> Deserializer<'a, NoAnnot> {
/// let data = "{ x = 1, y = 1 + 1 }";
/// let point = from_str(data)
/// .type_annotation(&ty)
- /// .parse::<HashMap<String, usize>>()?;
+ /// .parse::<HashMap<String, u64>>()?;
/// assert_eq!(point.get("y"), Some(&2));
///
/// // Invalid data fails the type validation; deserialization would have succeeded otherwise.
@@ -138,7 +138,7 @@ impl<'a> Deserializer<'a, NoAnnot> {
/// assert!(
/// from_str(invalid_data)
/// .type_annotation(&ty)
- /// .parse::<HashMap<String, usize>>()
+ /// .parse::<HashMap<String, u64>>()
/// .is_err()
/// );
/// # Ok(())