Debian Codegraph @

test-crates/cffi-mixed/src/lib.rs

raw
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 add_points(p1: Point, p2: Point) -> Point {
21 Point {
22 x: p1.x + p2.x,
23 y: p1.y + p2.y,
24 }
25 }
26
27 #[no_mangle]
28 pub unsafe extern "C" fn is_in_range(point: Point, range: f32) -> bool {
29 (point.x.powi(2) + point.y.powi(2)).sqrt() <= range
30 }
31
32 #[no_mangle]
33 pub unsafe extern "C" fn print_foo(foo: *const Foo) {
34 println!(
35 "{}",
36 match *foo {
37 Foo::A => "a",
38 Foo::B => "b",
39 Foo::C => "c",
40 }
41 );
42 }