Debian Codegraph @

.cargo/vendor/cbindgen/tests/rust/swift_name.rs

raw
1 #[export_name="rust_print_hello_world"]
2 pub extern fn say_hello() {
3 println!("Hello, World!");
4 }
5
6 #[repr(C)]
7 pub struct SelfTypeTestStruct {
8 times: u8,
9 }
10
11 impl SelfTypeTestStruct {
12 #[export_name="SelfTypeTestStruct_should_exist_ref"]
13 #[no_mangle]
14 pub extern fn should_exist_ref(&self) {
15 println!("should_exist_ref");
16 }
17
18 #[export_name="SelfTypeTestStruct_should_exist_ref_mut"]
19 #[no_mangle]
20 pub extern fn should_exist_ref_mut(&mut self) {
21 println!("should_exist_ref_mut");
22 }
23
24 #[export_name="SelfTypeTestStruct_should_not_exist_box"]
25 #[no_mangle]
26 pub extern fn should_not_exist_box(self: Box<SelfTypeTestStruct>) {
27 println!("should_not_exist_box");
28 }
29
30 #[export_name="SelfTypeTestStruct_should_not_exist_return_box"]
31 #[no_mangle]
32 pub extern fn should_not_exist_box() -> Box<Self> {
33 println!("should_not_exist_box");
34 }
35
36 #[export_name="SelfTypeTestStruct_should_exist_annotated_self"]
37 #[no_mangle]
38 pub extern fn should_exist_annotated_self(self: Self) {
39 println!("should_exist_annotated_self");
40 }
41
42 #[export_name="SelfTypeTestStruct_should_exist_annotated_mut_self"]
43 #[no_mangle]
44 #[allow(unused_mut)]
45 pub extern fn should_exist_annotated_mut_self(mut self: Self) {
46 println!("should_exist_annotated_mut_self");
47 }
48
49 #[export_name="SelfTypeTestStruct_should_exist_annotated_by_name"]
50 #[no_mangle]
51 pub extern fn should_exist_annotated_by_name(self: SelfTypeTestStruct) {
52 println!("should_exist_annotated_by_name");
53 }
54
55 #[export_name="SelfTypeTestStruct_should_exist_annotated_mut_by_name"]
56 #[no_mangle]
57 #[allow(unused_mut)]
58 pub extern fn should_exist_annotated_mut_by_name(mut self: SelfTypeTestStruct) {
59 println!("should_exist_annotated_mut_by_name");
60 }
61
62 #[export_name="SelfTypeTestStruct_should_exist_unannotated"]
63 #[no_mangle]
64 pub extern fn should_exist_unannotated(self) {
65 println!("should_exist_unannotated");
66 }
67
68 #[export_name="SelfTypeTestStruct_should_exist_mut_unannotated"]
69 #[no_mangle]
70 #[allow(unused_mut)]
71 pub extern fn should_exist_mut_unannotated(mut self) {
72 println!("should_exist_mut_unannotated");
73 }
74 }
75
76 #[no_mangle]
77 #[allow(unused_variables)]
78 pub extern fn free_function_should_exist_ref(test_struct: &SelfTypeTestStruct) {
79 println!("free_function_should_exist_ref");
80 }
81
82 #[no_mangle]
83 #[allow(unused_variables)]
84 pub extern fn free_function_should_exist_ref_mut(test_struct: &mut SelfTypeTestStruct) {
85 println!("free_function_should_exist_ref_mut");
86 }
87
88 #[no_mangle]
89 pub extern fn unnamed_argument(_: &mut SelfTypeTestStruct) {
90 println!("unnamed_argument");
91 }
92
93 #[no_mangle]
94 #[allow(unused_variables)]
95 pub extern fn free_function_should_not_exist_box(boxed: Box<SelfTypeTestStruct>) {
96 println!("free_function_should_not_exist_box");
97 }
98
99 #[no_mangle]
100 #[allow(unused_variables)]
101 pub extern fn free_function_should_exist_annotated_by_name(test_struct: SelfTypeTestStruct) {
102 println!("free_function_should_exist_annotated_by_name");
103 }
104
105 #[no_mangle]
106 #[allow(unused_mut)]
107 #[allow(unused_variables)]
108 pub extern fn free_function_should_exist_annotated_mut_by_name(mut test_struct: SelfTypeTestStruct) {
109 println!("free_function_should_exist_annotated_mut_by_name");
110 }
111
112 struct Opaque {
113 times: u8
114 }
115
116 #[repr(C)]
117 pub struct PointerToOpaque { ptr: *mut Opaque }
118
119 impl PointerToOpaque {
120 #[export_name="PointerToOpaque_create"]
121 pub extern fn create(times: u8) -> PointerToOpaque {
122 PointerToOpaque { ptr: Box::into_raw(Box::new(Opaque { times })) }
123 }
124
125 #[export_name="PointerToOpaque_sayHello"]
126 pub extern fn say_hello(self: PointerToOpaque) {
127 if let Some(nonnull) = std::ptr::NonNull::new(self.ptr) {
128 for _ in 0 .. unsafe { nonnull.as_ref().times } {
129 println!("Hello!")
130 }
131 }
132 }
133 }