2020-09-18 00:52:13 +00:00
|
|
|
use crate::{InputValueError, InputValueResult, Scalar, ScalarType, Value};
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-05-19 05:27:01 +00:00
|
|
|
/// The `Boolean` scalar type represents `true` or `false`.
|
2020-09-18 00:52:13 +00:00
|
|
|
#[Scalar(internal, name = "Boolean")]
|
2020-04-27 09:58:10 +00:00
|
|
|
impl ScalarType for bool {
|
2020-05-11 13:47:24 +00:00
|
|
|
fn parse(value: Value) -> InputValueResult<Self> {
|
2020-03-01 10:54:34 +00:00
|
|
|
match value {
|
2020-05-11 13:47:24 +00:00
|
|
|
Value::Boolean(n) => Ok(n),
|
|
|
|
_ => Err(InputValueError::ExpectedType(value)),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn is_valid(value: &Value) -> bool {
|
|
|
|
match value {
|
|
|
|
Value::Boolean(_) => true,
|
|
|
|
_ => false,
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-26 10:34:43 +00:00
|
|
|
fn to_value(&self) -> Value {
|
|
|
|
Value::Boolean(*self)
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|
|
|
|
}
|