From f6430bf0ec64e9788bd66cb78d548725af89280c Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Fri, 15 Mar 2024 15:59:02 +1100 Subject: [PATCH] refactor(ffi): simply `set_comment` using `comments_mut` Instead of matching on the inner type of the interaction, use the higher level `comments_mut()` to access the hashmap. Signed-off-by: JP-Ellis --- rust/pact_ffi/src/mock_server/handles.rs | 27 +++++------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/rust/pact_ffi/src/mock_server/handles.rs b/rust/pact_ffi/src/mock_server/handles.rs index 91cfbfdde..336d5b7c8 100644 --- a/rust/pact_ffi/src/mock_server/handles.rs +++ b/rust/pact_ffi/src/mock_server/handles.rs @@ -2203,28 +2203,11 @@ ffi_fn!{ }; interaction.with_interaction(&|_, _, inner| { - if let Some(reqres) = inner.as_v4_http_mut() { - match &value { - Some(value) => reqres.comments.insert(key.to_string(), value.clone()), - None => reqres.comments.remove(key) - }; - Ok(()) - } else if let Some(message) = inner.as_v4_async_message_mut() { - match &value { - Some(value) => message.comments.insert(key.to_string(), value.clone()), - None => message.comments.remove(key) - }; - Ok(()) - } else if let Some(sync_message) = inner.as_v4_sync_message_mut() { - match &value { - Some(value) => sync_message.comments.insert(key.to_string(), value.clone()), - None => sync_message.comments.remove(key) - }; - Ok(()) - } else { - error!("Interaction is an unknown type, is {}", inner.type_of()); - Err(anyhow!("Interaction is an unknown type, is {}", inner.type_of())) - } + match &value { + Some(value) => inner.comments_mut().insert(key.to_string(), value.clone()), + None => inner.comments_mut().remove(key) + }; + Ok(()) }).unwrap_or(Err(anyhow!("Not value to unwrap"))).is_ok() } { false