Trait juniper::ResultExt
[−]
[src]
pub trait ResultExt<T, E: Display> { fn to_field_err(self) -> Result<T, String>; }
Helper trait to produce FieldResult
s
FieldResult
only have strings as errors as that's what's going out
in the GraphQL response. As such, all errors must be manually
converted to strings. Importing the ResultExt
macro and using its
only method to_field_err
can help with that:
use std::str::FromStr; use juniper::{FieldResult, ResultExt}; fn sample_fn(s: &str) -> FieldResult<i64> { i64::from_str(s).to_field_err() }
Alternatively, you can use the jtry!
macro in all places you'd
normally use the regular try!
macro:
#[macro_use] extern crate juniper; use std::str::FromStr; use juniper::{FieldResult, ResultExt}; fn sample_fn(s: &str) -> FieldResult<i64> { let value = jtry!(i64::from_str(s)); Ok(value) }
Required Methods
fn to_field_err(self) -> Result<T, String>
Convert the error to a string by using it's Display
implementation