Merge pull request #175 from MidasLamb/scalar-for-u32

Added u32 as ScalarType
This commit is contained in:
Sunli 2020-06-15 09:18:24 +08:00 committed by GitHub
commit b29493bd0d

View File

@ -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<Self> {
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 {