From 132390fa357f98e0437f90427fbf49779f3bea99 Mon Sep 17 00:00:00 2001 From: Fabian Stamm Date: Tue, 25 Apr 2023 08:55:57 +0200 Subject: [PATCH] Make result field of JRPCResult Optional --- package.json | 2 +- templates/Rust/src/lib.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c410bfa..4ecad40 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/jrpcgen", - "version": "1.2.12", + "version": "1.2.13", "main": "lib/index.js", "license": "MIT", "packageManager": "yarn@3.1.1", diff --git a/templates/Rust/src/lib.rs b/templates/Rust/src/lib.rs index 59b1839..d474895 100644 --- a/templates/Rust/src/lib.rs +++ b/templates/Rust/src/lib.rs @@ -40,7 +40,7 @@ pub struct JRPCError { pub struct JRPCResult { pub jsonrpc: String, pub id: String, - pub result: Value, + pub result: Option, pub error: Option, } @@ -76,8 +76,10 @@ impl JRPCClient { if let Some(result) = result { if let Some(error) = result.error { return Err(format!("Error while receiving result: {}", error.message).into()); + } else if let Some(result) = result.result { + return Ok(result); } else { - return Ok(result.result); + return Err(format!("No result received").into()); } } else { return Err("Error while receiving result".into()); @@ -133,7 +135,7 @@ impl JRPCSession { let result = JRPCResult { jsonrpc: "2.0".to_string(), id: request_id, - result: Value::Null, + result: None, error: Some(error), }; @@ -169,7 +171,7 @@ impl JRPCSession { .send(JRPCResult { jsonrpc: "2.0".to_string(), id: request.id.unwrap(), - result, + result: Some(result), error: None, }) .await;