From 11d7a8cbdb5e19d2a920a1bae9d6a9ae7093575d Mon Sep 17 00:00:00 2001 From: Midas Lambrichts Date: Sun, 14 Jun 2020 22:13:45 +0200 Subject: [PATCH] Added u32 as ScalarType --- src/scalars/integers.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/scalars/integers.rs b/src/scalars/integers.rs index 35f4be67..94ff5311 100644 --- a/src/scalars/integers.rs +++ b/src/scalars/integers.rs @@ -134,6 +134,29 @@ 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")] +impl ScalarType for u32 { + fn parse(value: Value) -> InputValueResult { + match value { + Value::Int(n) => Ok(n as Self), + Value::String(s) => Ok(s.parse()?), + _ => Err(InputValueError::ExpectedType(value)), + } + } + + fn is_valid(value: &Value) -> bool { + match value { + Value::Int(_) | Value::String(_) => true, + _ => false, + } + } + + fn to_value(&self) -> Value { + Value::String(self.to_string()) + } +} + /// 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")] impl ScalarType for u64 {