16021
|
1 |
pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;
|
|
2 |
|
16038
|
3 |
pub mod ffi;
|
|
4 |
pub mod other_mod;
|
|
5 |
|
16021
|
6 |
#[derive(Debug)]
|
|
7 |
#[repr(C)]
|
|
8 |
pub struct Point {
|
|
9 |
x: u64,
|
|
10 |
y: u64,
|
|
11 |
}
|
|
12 |
|
|
13 |
impl Point {
|
|
14 |
pub(crate) fn add(&mut self, rhs: &Point) {
|
|
15 |
self.x = self.x.wrapping_add(rhs.x);
|
|
16 |
self.y = self.y.wrapping_add(rhs.y);
|
|
17 |
}
|
|
18 |
}
|
|
19 |
|
|
20 |
#[no_mangle]
|
|
21 |
pub extern "C" fn add_point(lhs: Option<&mut Point>, rhs: Option<&Point>) {
|
|
22 |
if let (Some(p1), Some(p2)) = (lhs, rhs) {
|
|
23 |
p1.add(p2);
|
|
24 |
// Print something so we can let Ctest assert the output.
|
|
25 |
println!("add_point Result: {:?}", p1);
|
|
26 |
}
|
|
27 |
}
|
|
28 |
|
|
29 |
// simple test if the constant was exported by cbindgen correctly
|
|
30 |
#[no_mangle]
|
|
31 |
pub extern "C" fn is_magic_number(num: u64) -> bool {
|
|
32 |
num == MAGIC_NUMBER
|
|
33 |
}
|