| 1 |
#[repr(C)] |
| 2 |
pub struct Point { |
| 3 |
pub x: f32, |
| 4 |
pub y: f32, |
| 5 |
} |
| 6 |
|
| 7 |
#[repr(u32)] |
| 8 |
pub enum Foo { |
| 9 |
A = 1, |
| 10 |
B, |
| 11 |
C, |
| 12 |
} |
| 13 |
|
| 14 |
#[no_mangle] |
| 15 |
pub unsafe extern "C" fn get_origin() -> Point { |
| 16 |
Point { x: 0.0, y: 0.0 } |
| 17 |
} |
| 18 |
|
| 19 |
#[no_mangle] |
| 20 |
pub unsafe extern "C" fn is_in_range(point: Point, range: f32) -> bool { |
| 21 |
(point.x.powi(2) + point.y.powi(2)).sqrt() <= range |
| 22 |
} |
| 23 |
|
| 24 |
#[no_mangle] |
| 25 |
pub unsafe extern "C" fn print_foo(foo: *const Foo) { |
| 26 |
println!( |
| 27 |
"{}", |
| 28 |
match *foo { |
| 29 |
Foo::A => "a", |
| 30 |
Foo::B => "b", |
| 31 |
Foo::C => "c", |
| 32 |
} |
| 33 |
); |
| 34 |
} |