tools/corrosion/test/cbindgen/rust2cpp/rust/src/lib.rs
author unC0Rr
Wed, 20 Nov 2024 21:37:47 +0100
branchtransitional_engine
changeset 16067 d903f8d2395a
parent 16050 6a3dc15b78b9
permissions -rw-r--r--
- Update corrosion - Implement installation of targets imported with corrosion

pub const MAGIC_NUMBER: u64 = 0xABCD_EFAB;

pub mod ffi;
pub mod other_mod;

#[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
}