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,
|
data: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
impl<T: Display> From<T> for FieldError {
|
impl<T: Display> From<T> for FieldError {
|
||||||
fn from(e: T) -> FieldError {
|
fn from(e: T) -> FieldError {
|
||||||
FieldError {
|
FieldError {
|
||||||
|
@ -115,6 +116,7 @@ impl<T: Display> From<T> for FieldError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
impl FieldError {
|
impl FieldError {
|
||||||
/// Construct a new error with additional data
|
/// 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`
|
/// The result of resolving the value of a field of type `T`
|
||||||
pub type FieldResult<T> = Result<T, FieldError>;
|
pub type FieldResult<T> = Result<T, FieldError>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue