Skip to content

Commit

Permalink
Remove support for integers smaller than i64
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
matthiasbeyer committed Mar 19, 2021
1 parent 9953c9b commit d89111d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 69 deletions.
6 changes: 0 additions & 6 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,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),
Expand Down Expand Up @@ -352,9 +349,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),
Expand Down
6 changes: 0 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use std::result;
#[derive(Debug)]
pub enum Unexpected {
Bool(bool),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
I128(i128),
Float(f64),
Expand All @@ -25,9 +22,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),
Expand Down
63 changes: 6 additions & 57 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use std::fmt::Display;
pub enum ValueKind {
Nil,
Boolean(bool),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
I128(i128),
Float(f64),
Expand Down Expand Up @@ -55,19 +52,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)
}
}

Expand Down Expand Up @@ -130,9 +127,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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),

Expand Down Expand Up @@ -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 }),
Expand Down Expand Up @@ -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()),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit d89111d

Please sign in to comment.