Skip to content

Commit

Permalink
Feedback on making code cleaner by avoiding needing explicit MessageF…
Browse files Browse the repository at this point in the history
…ield.
  • Loading branch information
PLeVasseur committed Jan 30, 2024
1 parent 3610926 commit c1f21c9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/rpc/rpcmapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
********************************************************************************/

use protobuf::well_known_types::any::Any;
use protobuf::MessageField;
use protobuf::MessageFull;
use std::default::Default;
use std::fmt;
Expand Down Expand Up @@ -84,7 +83,7 @@ impl RpcMapper {
T: MessageFull + Default,
{
let message = response?; // Directly returns in case of error
let MessageField(Some(payload)) = message.payload else {
let Some(payload) = message.payload.as_ref() else {
return Err(RpcMapperError::InvalidPayload(
"Payload is empty".to_string(),
));
Expand Down Expand Up @@ -129,13 +128,12 @@ impl RpcMapper {
// TODO This entire thing feels klunky and kludgy; this needs to be revisited...
pub fn map_response_to_result(response: RpcClientResult) -> RpcPayloadResult {
let message = response?; // Directly returns in case of error
let MessageField(Some(payload)) = message.payload else {
let Some(payload) = message.payload.as_ref() else {
return Err(RpcMapperError::InvalidPayload(
"Payload is empty".to_string(),
));
};
let payload = *payload;
Any::try_from(payload)
Any::try_from(*payload)
.map_err(|e| {
RpcMapperError::UnknownType(
format!("Couldn't decode payload into Any: {:?}", e).to_string(),
Expand Down

0 comments on commit c1f21c9

Please sign in to comment.