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