async-graphql/src/scalars/bool.rs

30 lines
669 B
Rust
Raw Normal View History

2020-03-03 11:15:18 +00:00
use crate::{Result, Scalar, Value};
2020-03-01 10:54:34 +00:00
2020-03-02 00:24:49 +00:00
impl Scalar for bool {
2020-03-01 10:54:34 +00:00
fn type_name() -> &'static str {
2020-03-03 11:15:18 +00:00
"Boolean"
2020-03-01 10:54:34 +00:00
}
2020-03-03 11:15:18 +00:00
fn description() -> Option<&'static str> {
Some("The `Boolean` scalar type represents `true` or `false`.")
}
2020-03-04 02:38:07 +00:00
fn parse(value: &Value) -> Option<Self> {
2020-03-01 10:54:34 +00:00
match value {
2020-03-04 02:38:07 +00:00
Value::Boolean(n) => Some(*n),
2020-03-03 11:15:18 +00:00
_ => None,
2020-03-01 10:54:34 +00:00
}
}
2020-03-04 02:38:07 +00:00
fn parse_from_json(value: &serde_json::Value) -> Option<Self> {
2020-03-01 16:52:05 +00:00
match value {
2020-03-04 02:38:07 +00:00
serde_json::Value::Bool(n) => Some(*n),
2020-03-03 11:15:18 +00:00
_ => None,
2020-03-01 16:52:05 +00:00
}
}
2020-03-02 00:24:49 +00:00
fn to_json(&self) -> Result<serde_json::Value> {
Ok((*self).into())
2020-03-01 10:54:34 +00:00
}
}