diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-03-18 13:22:03 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-07-10 15:36:15 +0200 |
commit | 2b14af663470354cc25b075a5b787c54d6c5d93e (patch) | |
tree | b1a63cf53282147e3806504a97bb24133896d5a1 | |
parent | 4b21043c8c5ce28593ae0a92d84daacc815a9728 (diff) |
Remove support for integers smaller than i64
All our backend crates do not support integers smaller than i64, so
there's no point in supporting them either.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | src/de.rs | 6 | ||||
-rw-r--r-- | src/error.rs | 6 | ||||
-rw-r--r-- | src/value.rs | 63 |
3 files changed, 6 insertions, 69 deletions
@@ -18,9 +18,6 @@ impl<'de> de::Deserializer<'de> for Value { // Deserialize based on the underlying type match self.kind { ValueKind::Nil => visitor.visit_unit(), - ValueKind::I8(i) => visitor.visit_i8(i), - ValueKind::I16(i) => visitor.visit_i16(i), - ValueKind::I32(i) => visitor.visit_i32(i), ValueKind::I64(i) => visitor.visit_i64(i), ValueKind::I128(i) => visitor.visit_i128(i), ValueKind::Boolean(b) => visitor.visit_bool(b), @@ -348,9 +345,6 @@ impl<'de> de::Deserializer<'de> for Config { // Deserialize based on the underlying type match self.cache.kind { ValueKind::Nil => visitor.visit_unit(), - ValueKind::I8(i) => visitor.visit_i8(i), - ValueKind::I16(i) => visitor.visit_i16(i), - ValueKind::I32(i) => visitor.visit_i32(i), ValueKind::I64(i) => visitor.visit_i64(i), ValueKind::I128(i) => visitor.visit_i128(i), ValueKind::Boolean(b) => visitor.visit_bool(b), diff --git a/src/error.rs b/src/error.rs index 6751e05..db5813e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,9 +8,6 @@ use serde::ser; #[derive(Debug)] pub enum Unexpected { Bool(bool), - I8(i8), - I16(i16), - I32(i32), I64(i64), I128(i128), Float(f64), @@ -24,9 +21,6 @@ impl fmt::Display for Unexpected { fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { match *self { Unexpected::Bool(b) => write!(f, "boolean `{}`", b), - Unexpected::I8(i) => write!(f, "integer 8 bit `{}`", i), - Unexpected::I16(i) => write!(f, "integer 16 bit `{}`", i), - Unexpected::I32(i) => write!(f, "integer 32 bit `{}`", i), Unexpected::I64(i) => write!(f, "integer 64 bit `{}`", i), Unexpected::I128(i) => write!(f, "integer 128 bit `{}`", i), Unexpected::Float(v) => write!(f, "floating point `{}`", v), diff --git a/src/value.rs b/src/value.rs index a584bda..a57f899 100644 --- a/src/value.rs +++ b/src/value.rs @@ -15,9 +15,6 @@ use crate::error::*; pub enum ValueKind { Nil, Boolean(bool), - I8(i8), - I16(i16), - I32(i32), I64(i64), I128(i128), Float(f64), @@ -61,19 +58,19 @@ impl<'a> From<&'a str> for ValueKind { impl From<i8> for ValueKind { fn from(value: i8) -> Self { - ValueKind::I8(value) + ValueKind::I64(value as i64) } } impl From<i16> for ValueKind { fn from(value: i16) -> Self { - ValueKind::I16(value) + ValueKind::I64(value as i64) } } impl From<i32> for ValueKind { fn from(value: i32) -> Self { - ValueKind::I32(value) + ValueKind::I64(value as i64) } } @@ -125,9 +122,6 @@ impl Display for ValueKind { match *self { ValueKind::String(ref value) => write!(f, "{}", value), ValueKind::Boolean(value) => write!(f, "{}", value), - ValueKind::I8(value) => write!(f, "{}", value), - ValueKind::I16(value) => write!(f, "{}", value), - ValueKind::I32(value) => write!(f, "{}", value), ValueKind::I64(value) => write!(f, "{}", value), ValueKind::I128(value) => write!(f, "{}", value), ValueKind::Float(value) => write!(f, "{}", value), @@ -192,9 +186,6 @@ impl Value { pub fn into_bool(self) -> Result<bool> { match self.kind { ValueKind::Boolean(value) => Ok(value), - ValueKind::I8(value) => Ok(value != 0), - ValueKind::I16(value) => Ok(value != 0), - ValueKind::I32(value) => Ok(value != 0), ValueKind::I64(value) => Ok(value != 0), ValueKind::I128(value) => Ok(value != 0), ValueKind::Float(value) => Ok(value != 0.0), @@ -236,9 +227,6 @@ impl Value { // FIXME: Should this not be `try_into_*` ? pub fn into_int(self) -> Result<i64> { match self.kind { - ValueKind::I8(value) => Ok(value as i64), - ValueKind::I16(value) => Ok(value as i64), - ValueKind::I32(value) => Ok(value as i64), ValueKind::I64(value) => Ok(value), ValueKind::I128(value) => Err(ConfigError::invalid_type( self.origin, @@ -288,9 +276,6 @@ impl Value { /// Returns `self` into an i128, if possible. pub fn into_int128(self) -> Result<i128> { match self.kind { - ValueKind::I8(value) => Ok(value as i128), - ValueKind::I16(value) => Ok(value as i128), - ValueKind::I32(value) => Ok(value as i128), ValueKind::I64(value) => Ok(value as i128), ValueKind::I128(value) => Ok(value), @@ -356,9 +341,6 @@ impl Value { } } - ValueKind::I8(value) => Ok(value as f64), - ValueKind::I16(value) => Ok(value as f64), - ValueKind::I32(value) => Ok(value as f64), ValueKind::I64(value) => Ok(value as f64), ValueKind::I128(value) => Ok(value as f64), ValueKind::Boolean(value) => Ok(if value { 1.0 } else { 0.0 }), @@ -389,9 +371,6 @@ impl Value { ValueKind::String(value) => Ok(value), ValueKind::Boolean(value) => Ok(value.to_string()), - ValueKind::I8(value) => Ok(value.to_string()), - ValueKind::I16(value) => Ok(value.to_string()), - ValueKind::I32(value) => Ok(value.to_string()), ValueKind::I64(value) => Ok(value.to_string()), ValueKind::I128(value) => Ok(value.to_string()), ValueKind::Float(value) => Ok(value.to_string()), @@ -432,21 +411,6 @@ impl Value { Unexpected::Str(value), "an array", )), - ValueKind::I8(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I8(value), - "an array", - )), - ValueKind::I16(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I16(value), - "an array", - )), - ValueKind::I32(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I32(value), - "an array", - )), ValueKind::I64(value) => Err(ConfigError::invalid_type( self.origin, Unexpected::I64(value), @@ -492,21 +456,6 @@ impl Value { Unexpected::Str(value), "a map", )), - ValueKind::I8(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I8(value), - "a map", - )), - ValueKind::I16(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I16(value), - "a map", - )), - ValueKind::I32(value) => Err(ConfigError::invalid_type( - self.origin, - Unexpected::I32(value), - "a map", - )), ValueKind::I64(value) => Err(ConfigError::invalid_type( self.origin, Unexpected::I64(value), @@ -558,17 +507,17 @@ impl<'de> Deserialize<'de> for Value { #[inline] fn visit_i8<E>(self, value: i8) -> ::std::result::Result<Value, E> { - Ok((value).into()) + Ok((value as i64).into()) } #[inline] fn visit_i16<E>(self, value: i16) -> ::std::result::Result<Value, E> { - Ok((value).into()) + Ok((value as i64).into()) } #[inline] fn visit_i32<E>(self, value: i32) -> ::std::result::Result<Value, E> { - Ok((value).into()) + Ok((value as i64).into()) } #[inline] |