async-graphql/src/scalars/url.rs

23 lines
479 B
Rust
Raw Normal View History

2020-03-24 10:54:22 +00:00
use crate::{impl_scalar_internal, JsonWriter, Result, Scalar, Value};
2020-03-20 03:56:08 +00:00
use url::Url;
impl Scalar for Url {
fn type_name() -> &'static str {
"Url"
}
fn parse(value: &Value) -> Option<Self> {
match value {
Value::String(s) => Some(Url::parse(s).ok()?),
_ => None,
}
}
2020-03-24 10:54:22 +00:00
fn to_json(&self, w: &mut JsonWriter) -> Result<()> {
w.string(&self.to_string());
Ok(())
2020-03-20 03:56:08 +00:00
}
}
impl_scalar_internal!(Url);