Skip to content

Commit

Permalink
feat: Add functions for Pact handle -> pointer compatibility #333
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed Nov 13, 2023
1 parent 32cfd51 commit c172bcb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rust/pact_ffi/src/mock_server/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ pub extern fn pactffi_new_pact(consumer_name: *const c_char, provider_name: *con
PactHandle::new(consumer, provider)
}

ffi_fn! {
/// Returns a mutable pointer to a Pact model which has been cloned from the Pact handle's inner
/// Pact model. The returned Pact model must be freed with the `pactffi_pact_model_delete`
/// function when no longer needed.
fn pactffi_pact_handle_to_pointer(pact: PactHandle) -> *mut crate::models::Pact {
pact.with_pact(&|_, inner| {
ptr::raw_to(crate::models::Pact::new(inner.pact.boxed()))
}).unwrap_or(std::ptr::null_mut())
} {
std::ptr::null_mut()
}
}

/// Creates a new HTTP Interaction and returns a handle to it.
///
/// * `description` - The interaction description. It needs to be unique for each interaction.
Expand Down Expand Up @@ -994,6 +1007,17 @@ pub extern fn pactffi_with_specification(pact: PactHandle, version: PactSpecific
}).unwrap_or(false)
}

ffi_fn! {
/// Returns the Pact specification enum that the Pact is for.
fn pactffi_handle_get_pact_spec_version(pact: PactHandle) -> PactSpecification {
pact.with_pact(&|_, inner| {
inner.specification_version
}).unwrap_or(PactSpecification::Unknown)
} {
PactSpecification::Unknown
}
}

/// Sets the additional metadata on the Pact file. Common uses are to add the client library details such as the name and version
/// Returns false if the interaction or Pact can't be modified (i.e. the mock server for it has already started)
///
Expand Down

0 comments on commit c172bcb

Please sign in to comment.