1--- 2source: macro/src/lib.rs 3assertion_line: 1069 4expression: "rustfmt_code(&gen_bridge(parse_quote! {\n mod ffi\n {\n pub struct TestingStruct { x: i32, y: i32, } pub trait\n TesterTrait: std::marker::Send\n {\n fn test_trait_fn(&self, x: i32) -> i32; fn\n test_void_trait_fn(&self); fn\n test_struct_trait_fn(&self, s: TestingStruct) -> i32; fn\n test_slice_trait_fn(&self, s: &[u8]) -> i32;\n } pub struct Wrapper { cant_be_empty: bool, } impl Wrapper\n {\n pub fn test_with_trait(t: impl TesterTrait, x: i32) -> i32\n { t.test_void_trait_fn(); t.test_trait_fn(x) } pub fn\n test_trait_with_struct(t: impl TesterTrait) -> i32\n {\n let arg = TestingStruct { x: 1, y: 5, };\n t.test_struct_trait_fn(arg)\n }\n }\n }\n }).to_token_stream().to_string())" 5--- 6mod ffi { 7 #[repr(C)] 8 pub struct TestingStruct { 9 x: i32, 10 y: i32, 11 } 12 pub trait TesterTrait: std::marker::Send { 13 fn test_trait_fn(&self, x: i32) -> i32; 14 fn test_void_trait_fn(&self); 15 fn test_struct_trait_fn(&self, s: TestingStruct) -> i32; 16 fn test_slice_trait_fn(&self, s: &[u8]) -> i32; 17 } 18 #[repr(C)] 19 pub struct Wrapper { 20 cant_be_empty: bool, 21 } 22 impl Wrapper { 23 pub fn test_with_trait(t: impl TesterTrait, x: i32) -> i32 { 24 t.test_void_trait_fn(); 25 t.test_trait_fn(x) 26 } 27 pub fn test_trait_with_struct(t: impl TesterTrait) -> i32 { 28 let arg = TestingStruct { x: 1, y: 5 }; 29 t.test_struct_trait_fn(arg) 30 } 31 } 32 use core::ffi::c_void; 33 use diplomat_runtime::*; 34 #[no_mangle] 35 extern "C" fn Wrapper_test_with_trait(t: DiplomatTraitStruct_TesterTrait, x: i32) -> i32 { 36 Wrapper::test_with_trait(t, x) 37 } 38 #[no_mangle] 39 extern "C" fn Wrapper_test_trait_with_struct(t: DiplomatTraitStruct_TesterTrait) -> i32 { 40 Wrapper::test_trait_with_struct(t) 41 } 42 #[repr(C)] 43 pub struct TesterTrait_VTable { 44 pub destructor: Option<unsafe extern "C" fn(*const c_void)>, 45 pub size: usize, 46 pub alignment: usize, 47 pub run_test_trait_fn_callback: unsafe extern "C" fn(*const c_void, i32) -> i32, 48 pub run_test_void_trait_fn_callback: unsafe extern "C" fn(*const c_void), 49 pub run_test_struct_trait_fn_callback: 50 unsafe extern "C" fn(*const c_void, TestingStruct) -> i32, 51 pub run_test_slice_trait_fn_callback: 52 unsafe extern "C" fn(*const c_void, diplomat_runtime::DiplomatSlice<u8>) -> i32, 53 } 54 #[repr(C)] 55 pub struct DiplomatTraitStruct_TesterTrait { 56 data: *const c_void, 57 pub vtable: TesterTrait_VTable, 58 } 59 unsafe impl std::marker::Send for DiplomatTraitStruct_TesterTrait {} 60 impl TesterTrait for DiplomatTraitStruct_TesterTrait { 61 fn test_trait_fn(&self, x: i32) -> i32 { 62 unsafe { ((self.vtable).run_test_trait_fn_callback)(self.data, x) } 63 } 64 fn test_void_trait_fn(&self) { 65 unsafe { 66 ((self.vtable).run_test_void_trait_fn_callback)(self.data); 67 } 68 } 69 fn test_struct_trait_fn(&self, s: TestingStruct) -> i32 { 70 unsafe { ((self.vtable).run_test_struct_trait_fn_callback)(self.data, s) } 71 } 72 fn test_slice_trait_fn(&self, s: &[u8]) -> i32 { 73 unsafe { 74 let s: diplomat_runtime::DiplomatSlice<u8> = s.into(); 75 ((self.vtable).run_test_slice_trait_fn_callback)(self.data, s) 76 } 77 } 78 } 79 impl Drop for DiplomatTraitStruct_TesterTrait { 80 fn drop(&mut self) { 81 if let Some(destructor) = self.vtable.destructor { 82 unsafe { 83 (destructor)(self.data); 84 } 85 } 86 } 87 } 88} 89