diff options
Diffstat (limited to 'core/ops.rs')
-rw-r--r-- | core/ops.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/core/ops.rs b/core/ops.rs index 3af60d072..867bb5210 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -74,11 +74,16 @@ pub enum Op { } #[derive(Serialize)] -pub struct OpResult<R>(Option<R>, Option<OpError>); +#[serde(untagged)] +pub enum OpResult<R> { + Ok(R), + Err(OpError), +} #[derive(Serialize)] #[serde(rename_all = "camelCase")] pub struct OpError { + #[serde(rename = "$err_class_name")] class_name: &'static str, message: String, } @@ -88,14 +93,11 @@ pub fn serialize_op_result<R: Serialize + 'static>( state: Rc<RefCell<OpState>>, ) -> OpResponse { OpResponse::Value(Box::new(match result { - Ok(v) => OpResult::<R>(Some(v), None), - Err(err) => OpResult::<R>( - None, - Some(OpError { - class_name: (state.borrow().get_error_class_fn)(&err), - message: err.to_string(), - }), - ), + Ok(v) => OpResult::Ok(v), + Err(err) => OpResult::Err(OpError { + class_name: (state.borrow().get_error_class_fn)(&err), + message: err.to_string(), + }), })) } |