From 5dfc12469a8e28a7ba301d6505c1373bee1ed5a5 Mon Sep 17 00:00:00 2001 From: Sunli Date: Mon, 15 Jun 2020 09:26:43 +0800 Subject: [PATCH] Update integers.rs --- src/scalars/integers.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/scalars/integers.rs b/src/scalars/integers.rs index 94ff5311..72820db1 100644 --- a/src/scalars/integers.rs +++ b/src/scalars/integers.rs @@ -134,12 +134,17 @@ impl ScalarType for i64 { } } -/// The `Int64` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^64) and 2^64 - 1. -#[Scalar(internal, name = "Int64")] +/// The `UInt64` scalar type represents non-fractional signed whole numeric values. Int can represent values between 0 and 2^64. +#[Scalar(internal, name = "UInt64")] impl ScalarType for u32 { fn parse(value: Value) -> InputValueResult { match value { - Value::Int(n) => Ok(n as Self), + Value::Int(n) => { + if n < 0 { + return Err(InputValueError::Custom("Expect a positive number.".into())); + } + Ok(n as Self) + } Value::String(s) => Ok(s.parse()?), _ => Err(InputValueError::ExpectedType(value)), } @@ -157,12 +162,17 @@ impl ScalarType for u32 { } } -/// The `Int64` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^64) and 2^64 - 1. -#[Scalar(internal, name = "Int64")] +/// The `UInt64` scalar type represents non-fractional signed whole numeric values. Int can represent values between 0 and 2^64. +#[Scalar(internal, name = "UInt64")] impl ScalarType for u64 { fn parse(value: Value) -> InputValueResult { match value { - Value::Int(n) => Ok(n as Self), + Value::Int(n) => { + if n < 0 { + return Err(InputValueError::Custom("Expect a positive number.".into())); + } + Ok(n as Self) + } Value::String(s) => Ok(s.parse()?), _ => Err(InputValueError::ExpectedType(value)), }