ferment_interfaces/
fermented.rs

1pub mod types {
2    use crate::{boxed, FFIConversion, OpaqueContext, OpaqueContextMut};
3
4    #[allow(non_camel_case_types)]
5    pub type OpaqueContext_FFI = OpaqueContext;
6    #[allow(non_camel_case_types)]
7    pub type OpaqueContextMut_FFI = OpaqueContextMut;
8
9    impl FFIConversion<OpaqueContext_FFI> for OpaqueContext {
10        unsafe fn ffi_from_const(ffi: *const Self) -> OpaqueContext_FFI {
11            *ffi
12        }
13
14        unsafe fn ffi_to_const(obj: OpaqueContext_FFI) -> *const Self {
15            obj as *const _
16        }
17
18        unsafe fn ffi_from(ffi: *mut Self) -> OpaqueContext_FFI {
19            *ffi
20        }
21
22        unsafe fn ffi_to(obj: OpaqueContext_FFI) -> *mut Self {
23            // Converting a const pointer to a mut pointer and then writing to it can lead to undefined
24            // behavior if the original memory location wasn't meant to be mutable
25            obj as *mut _
26        }
27
28        unsafe fn destroy(_ffi: *mut Self) {
29            // No destroy no ownership here
30        }
31    }
32
33    impl FFIConversion<OpaqueContextMut_FFI> for OpaqueContextMut {
34        unsafe fn ffi_from_const(ffi: *const Self) -> OpaqueContextMut_FFI {
35            *ffi
36        }
37
38        unsafe fn ffi_to_const(obj: OpaqueContextMut_FFI) -> *const Self {
39            obj as *const _
40        }
41
42        unsafe fn ffi_from(ffi: *mut Self) -> OpaqueContextMut_FFI {
43            *ffi
44        }
45
46        unsafe fn ffi_to(obj: OpaqueContextMut_FFI) -> *mut Self {
47            // Converting a const pointer to a mut pointer and then writing to it can lead to undefined
48            // behavior if the original memory location wasn't meant to be mutable
49            boxed(obj)
50        }
51    }
52}