tools/corrosion/test/cbindgen/rust2cpp/rust/src/lib.rs
branchtransitional_engine
changeset 16021 6a3dc15b78b9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tools/corrosion/test/cbindgen/rust2cpp/rust/src/lib.rs	Wed Aug 28 15:31:51 2024 +0200
@@ -0,0 +1,30 @@
+pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;
+
+#[derive(Debug)]
+#[repr(C)]
+pub struct Point {
+    x: u64,
+    y: u64,
+}
+
+impl Point {
+    pub(crate) fn add(&mut self, rhs: &Point) {
+        self.x = self.x.wrapping_add(rhs.x);
+        self.y = self.y.wrapping_add(rhs.y);
+    }
+}
+
+#[no_mangle]
+pub extern "C" fn add_point(lhs: Option<&mut Point>, rhs: Option<&Point>) {
+    if let (Some(p1), Some(p2)) = (lhs, rhs) {
+        p1.add(p2);
+        // Print something so we can let Ctest assert the output.
+        println!("add_point Result: {:?}", p1);
+    }
+}
+
+// simple test if the constant was exported by cbindgen correctly
+#[no_mangle]
+pub extern "C" fn is_magic_number(num: u64) -> bool {
+    num == MAGIC_NUMBER
+}