From 40a831413b548c436ff0349cb2a23a224ff68b3b Mon Sep 17 00:00:00 2001 From: "hinto.janai" Date: Tue, 19 Nov 2024 17:48:54 -0500 Subject: [PATCH] `fn error() -> String` -> `error!() -> &'static str` --- rpc/types/src/bin.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/rpc/types/src/bin.rs b/rpc/types/src/bin.rs index 6f56bca..899f27e 100644 --- a/rpc/types/src/bin.rs +++ b/rpc/types/src/bin.rs @@ -291,8 +291,13 @@ impl EpeeObjectBuilder for __GetBlocksResponseEpeeBuilder { fn finish(self) -> error::Result { /// The error returned when a required field is missing. - fn error(name: &'static str) -> error::Error { - error::Error::Value(format!("Required field was not found: {name}")) + macro_rules! error { + ($field_name:literal) => { + error::Error::Format(concat!( + "Required field was not found: ", + stringify!($field_name) + )) + }; } // INVARIANT: @@ -302,11 +307,11 @@ impl EpeeObjectBuilder for __GetBlocksResponseEpeeBuilder { // Deserialize the common fields. let header = GetBlocksResponseHeader { - status: self.status.ok_or_else(|| error("status"))?, - untrusted: self.untrusted.ok_or_else(|| error("untrusted"))?, + status: self.status.ok_or(error!("status"))?, + untrusted: self.untrusted.ok_or(error!("untrusted"))?, blocks: self.blocks.unwrap_or_default(), - start_height: self.start_height.ok_or_else(|| error("start_height"))?, - current_height: self.current_height.ok_or_else(|| error("current_height"))?, + start_height: self.start_height.ok_or(error!("start_height"))?, + current_height: self.current_height.ok_or(error!("current_height"))?, output_indices: self.output_indices.unwrap_or_default(), daemon_time: self.daemon_time.unwrap_or_default(), };