Implement the simplest FieldResultExt w/o updating tests

This commit is contained in:
Kevin Stenerson 2018-03-16 11:00:27 -06:00
parent 63d8a3d1a0
commit aff14c9a57

View file

@ -107,6 +107,7 @@ pub struct FieldError {
data: Value,
}
/*
impl<T: Display> From<T> for FieldError {
fn from(e: T) -> FieldError {
FieldError {
@ -115,6 +116,7 @@ impl<T: Display> From<T> for FieldError {
}
}
}
*/
impl FieldError {
/// Construct a new error with additional data
@ -168,6 +170,21 @@ impl FieldError {
}
}
pub trait FieldResultExt<T, E> {
fn fmt_err(self) -> Result<T, FieldError>;
}
impl<T, E> FieldResultExt<T, E> for Result<T, E>
where E: Display
{
fn fmt_err(self) -> Result<T, FieldError> {
self.map_err(|e| FieldError {
message: format!("{}", e),
data: Value::null(),
})
}
}
/// The result of resolving the value of a field of type `T`
pub type FieldResult<T> = Result<T, FieldError>;