Skip to content

Commit

Permalink
refactor(ffi): simply set_comment using comments_mut
Browse files Browse the repository at this point in the history
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 <josh@jpellis.me>
  • Loading branch information
JP-Ellis committed Mar 15, 2024
1 parent f310e8e commit f6430bf
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions rust/pact_ffi/src/mock_server/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6430bf

Please sign in to comment.