1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use crate::{impl_scalar, GQLScalar, Result, Value}; macro_rules! impl_integer_scalars { ($($ty:ty),*) => { $( impl GQLScalar for $ty { fn type_name() -> &'static str { "Int" } fn description() -> Option<&'static str> { Some("The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1.") } fn parse(value: &Value) -> Option<Self> { match value { Value::Int(n) => Some(n.as_i64().unwrap() as Self), _ => None } } fn to_json(&self) -> Result<serde_json::Value> { Ok((*self).into()) } } impl_scalar!($ty); )* }; } impl_integer_scalars!(i8, i16, i32, i64, u8, u16, u32, u64);