Implement the simplest FieldResultExt w/o updating tests
This commit is contained in:
parent
63d8a3d1a0
commit
aff14c9a57
1 changed files with 17 additions and 0 deletions
|
@ -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>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue