diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-29 10:46:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-29 10:46:12 +0100 |
commit | f2399b73478c0409ab7599ef9d786a6ed58b3ebf (patch) | |
tree | c3909ed0dae1a37379aa1d68b9ab7d9fc44eb12c /src | |
parent | 971e65955229d27d91c0d51f858b1c3136b7594e (diff) | |
parent | 51077f338678d566aabc76543456c8bf6c04a03b (diff) |
Merge pull request #267 from danieleades/refactor/cast-lossless
use infallible integer conversions where available
Diffstat (limited to 'src')
-rw-r--r-- | src/ser.rs | 14 | ||||
-rw-r--r-- | src/value.rs | 30 |
2 files changed, 22 insertions, 22 deletions
@@ -98,15 +98,15 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer { } fn serialize_i8(self, v: i8) -> Result<Self::Ok> { - self.serialize_i64(v as i64) + self.serialize_i64(v.into()) } fn serialize_i16(self, v: i16) -> Result<Self::Ok> { - self.serialize_i64(v as i64) + self.serialize_i64(v.into()) } fn serialize_i32(self, v: i32) -> Result<Self::Ok> { - self.serialize_i64(v as i64) + self.serialize_i64(v.into()) } fn serialize_i64(self, v: i64) -> Result<Self::Ok> { @@ -114,15 +114,15 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer { } fn serialize_u8(self, v: u8) -> Result<Self::Ok> { - self.serialize_u64(v as u64) + self.serialize_u64(v.into()) } fn serialize_u16(self, v: u16) -> Result<Self::Ok> { - self.serialize_u64(v as u64) + self.serialize_u64(v.into()) } fn serialize_u32(self, v: u32) -> Result<Self::Ok> { - self.serialize_u64(v as u64) + self.serialize_u64(v.into()) } fn serialize_u64(self, v: u64) -> Result<Self::Ok> { @@ -138,7 +138,7 @@ impl<'a> ser::Serializer for &'a mut ConfigSerializer { } fn serialize_f32(self, v: f32) -> Result<Self::Ok> { - self.serialize_f64(v as f64) + self.serialize_f64(v.into()) } fn serialize_f64(self, v: f64) -> Result<Self::Ok> { diff --git a/src/value.rs b/src/value.rs index c88d8a9..2a274cb 100644 --- a/src/value.rs +++ b/src/value.rs @@ -60,19 +60,19 @@ impl<'a> From<&'a str> for ValueKind { impl From<i8> for ValueKind { fn from(value: i8) -> Self { - ValueKind::I64(value as i64) + ValueKind::I64(value.into()) } } impl From<i16> for ValueKind { fn from(value: i16) -> Self { - ValueKind::I64(value as i64) + ValueKind::I64(value.into()) } } impl From<i32> for ValueKind { fn from(value: i32) -> Self { - ValueKind::I64(value as i64) + ValueKind::I64(value.into()) } } @@ -90,19 +90,19 @@ impl From<i128> for ValueKind { impl From<u8> for ValueKind { fn from(value: u8) -> Self { - ValueKind::U64(value as u64) + ValueKind::U64(value.into()) } } impl From<u16> for ValueKind { fn from(value: u16) -> Self { - ValueKind::U64(value as u64) + ValueKind::U64(value.into()) } } impl From<u32> for ValueKind { fn from(value: u32) -> Self { - ValueKind::U64(value as u64) + ValueKind::U64(value.into()) } } @@ -322,9 +322,9 @@ impl Value { /// Returns `self` into an i128, if possible. pub fn into_int128(self) -> Result<i128> { match self.kind { - ValueKind::I64(value) => Ok(value as i128), + ValueKind::I64(value) => Ok(value.into()), ValueKind::I128(value) => Ok(value), - ValueKind::U64(value) => Ok(value as i128), + ValueKind::U64(value) => Ok(value.into()), ValueKind::U128(value) => Err(ConfigError::invalid_type( self.origin, Unexpected::U128(value), @@ -433,7 +433,7 @@ impl Value { /// Returns `self` into an u128, if possible. pub fn into_uint128(self) -> Result<u128> { match self.kind { - ValueKind::U64(value) => Ok(value as u128), + ValueKind::U64(value) => Ok(value.into()), ValueKind::U128(value) => Ok(value), ValueKind::I64(value) => Err(ConfigError::invalid_type( self.origin, @@ -698,17 +698,17 @@ impl<'de> Deserialize<'de> for Value { #[inline] fn visit_i8<E>(self, value: i8) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] fn visit_i16<E>(self, value: i16) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] fn visit_i32<E>(self, value: i32) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] @@ -723,17 +723,17 @@ impl<'de> Deserialize<'de> for Value { #[inline] fn visit_u8<E>(self, value: u8) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] fn visit_u16<E>(self, value: u16) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] fn visit_u32<E>(self, value: u32) -> ::std::result::Result<Value, E> { - Ok((value as i64).into()) + Ok((i64::from(value)).into()) } #[inline] |