1#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
2mod bindings_linux_x86_64;
3#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
4mod bindings_macos_aarch64;
5#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
6mod bindings_windows_x86_64;
7#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
8pub use bindings_linux_x86_64::*;
9#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
10pub use bindings_macos_aarch64::*;
11#[cfg(all(target_os = "windows", target_arch = "x86_64"))]
12pub use bindings_windows_x86_64::*;
13#[allow(clippy::len_without_is_empty)]
14pub trait FfiSlice {
15 fn as_ptr(&self) -> *const u8;
16 fn len(&self) -> usize;
17}
18pub trait FfiSliceMut {
19 fn as_mut_ptr(&mut self) -> *mut u8;
20 fn capacity(&self) -> usize;
21 unsafe fn set_len(&mut self, new_len: usize);
23}
24impl FfiSlice for &[u8] {
25 fn as_ptr(&self) -> *const u8 {
26 if <Self as FfiSlice>::len(self) == 0 {
27 std::ptr::null()
28 } else {
29 <[u8]>::as_ptr(self)
30 }
31 }
32 fn len(&self) -> usize {
33 <[u8]>::len(self)
34 }
35}
36impl FfiSliceMut for Vec<u8> {
37 fn as_mut_ptr(&mut self) -> *mut u8 {
38 if <Self as FfiSliceMut>::capacity(self) == 0 {
39 std::ptr::null_mut()
40 } else {
41 Vec::as_mut_ptr(self)
42 }
43 }
44 fn capacity(&self) -> usize {
45 Vec::capacity(self)
46 }
47 unsafe fn set_len(&mut self, new_len: usize) {
48 unsafe { Vec::set_len(self, new_len) }
49 }
50}