Skip to content

Commit

Permalink
Revert lossy conversions to use as
Browse files Browse the repository at this point in the history
The conversions in this changeset cannot use the `From<T>` trait
implementation because the conversion is lossy, either because they
involve converting a signed value to an unsigned value (`i32`⇒`u64`)
or because the convert from a larger data type to a smaller one
(`u64`⇒`i32`). In this case, the `as` type cast is necessary to perform
a bitwise conversion.

This coercion can cause negative values to become very large unsigned
values. This is intentional on line 90.
  • Loading branch information
neoeinstein committed Feb 21, 2018
1 parent c98cb48 commit d956b91
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions juniper/src/integrations/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'de> de::Deserialize<'de> for InputValue {
E: de::Error,
{
if value >= i64::from(i32::min_value()) && value <= i64::from(i32::max_value()) {
Ok(InputValue::int(i32::from(value)))
Ok(InputValue::int(value as i32))
} else {
Err(E::custom(format!("integer out of range")))
}
Expand All @@ -87,8 +87,8 @@ impl<'de> de::Deserialize<'de> for InputValue {
where
E: de::Error,
{
if value <= u64::from(i32::max_value()) {
self.visit_i64(i64::from(value))
if value <= i32::max_value() as u64 {
self.visit_i64(value as i64)
} else {
Err(E::custom(format!("integer out of range")))
}
Expand Down

0 comments on commit d956b91

Please sign in to comment.