1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#![warn(missing_docs)]
#![warn(missing_debug_implementations)]
#![warn(missing_copy_implementations)]
pub mod error;
pub mod log;
pub mod models;
pub(crate) mod util;
use crate::util::*;
use libc::c_char;
use models::message::Message;
use pact_matching::{self as pm, models::Interaction};
pub use pact_matching::Mismatch;
ffi_fn! {
fn match_message(msg_1: *const Message, msg_2: *const Message) -> *const Mismatches {
let msg_1: Box<dyn Interaction + Send> = unsafe { Box::from_raw(msg_1 as *mut Message) };
let msg_2: Box<dyn Interaction + Send> = unsafe { Box::from_raw(msg_2 as *mut Message) };
let mismatches = Mismatches(pm::match_message(&msg_1, &msg_2));
ptr::raw_to(mismatches) as *const Mismatches
} {
ptr::null_to::<Mismatches>() as *const Mismatches
}
}
ffi_fn! {
fn mismatches_get_iter(mismatches: *const Mismatches) -> *mut MismatchesIterator {
let mismatches = as_ref!(mismatches);
let iter = MismatchesIterator { current: 0, mismatches };
ptr::raw_to(iter)
} {
ptr::null_mut_to::<MismatchesIterator>()
}
}
ffi_fn! {
fn mismatches_delete(mismatches: *const Mismatches) {
ptr::drop_raw(mismatches as *mut Mismatches);
}
}
ffi_fn! {
fn mismatches_iter_next(iter: *mut MismatchesIterator) -> *const Mismatch {
let iter = as_mut!(iter);
let mismatches = as_ref!(iter.mismatches);
let index = iter.next();
let mismatch = mismatches
.0
.get(index)
.ok_or(anyhow::anyhow!("iter past the end of mismatches"))?;
mismatch as *const Mismatch
} {
ptr::null_to::<Mismatch>()
}
}
ffi_fn! {
fn mismatches_iter_delete(iter: *mut MismatchesIterator) {
ptr::drop_raw(iter);
}
}
ffi_fn! {
fn mismatch_to_json(mismatch: *const Mismatch) -> *const c_char {
let mismatch = as_ref!(mismatch);
let json = mismatch.to_json().to_string();
string::to_c(&json)? as *const c_char
} {
ptr::null_to::<c_char>()
}
}
ffi_fn! {
fn mismatch_type(mismatch: *const Mismatch) -> *const c_char {
let mismatch = as_ref!(mismatch);
let t = mismatch.mismatch_type();
string::to_c(&t)? as *const c_char
} {
ptr::null_to::<c_char>()
}
}
ffi_fn! {
fn mismatch_summary(mismatch: *const Mismatch) -> *const c_char {
let mismatch = as_ref!(mismatch);
let summary = mismatch.summary();
string::to_c(&summary)? as *const c_char
} {
ptr::null_to::<c_char>()
}
}
ffi_fn! {
fn mismatch_description(mismatch: *const Mismatch) -> *const c_char {
let mismatch = as_ref!(mismatch);
let description = mismatch.description();
string::to_c(&description)? as *const c_char
} {
ptr::null_to::<c_char>()
}
}
ffi_fn! {
fn mismatch_ansi_description(mismatch: *const Mismatch) -> *const c_char {
let mismatch = as_ref!(mismatch);
let ansi_description = mismatch.ansi_description();
string::to_c(&ansi_description)? as *const c_char
} {
ptr::null_to::<c_char>()
}
}
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct Mismatches(Vec<Mismatch>);
#[allow(missing_copy_implementations)]
#[allow(missing_debug_implementations)]
pub struct MismatchesIterator {
current: usize,
mismatches: *const Mismatches,
}
impl MismatchesIterator {
fn next(&mut self) -> usize {
let idx = self.current;
self.current += 1;
idx
}
}