1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use ::ffi_sdk::{ffi_utils::repr_c, FfiError};
pub(crate) trait RefCounted: Clone {
fn retain(&self) -> Self {
Clone::clone(self)
}
#[rustfmt::skip]
fn clone(&self) -> Self { Clone::clone(self)
}
}
impl<T: ?Sized> RefCounted for ::std::rc::Rc<T> {}
impl<T: ?Sized> RefCounted for ::std::sync::Arc<T> {}
pub(crate) trait FfiResultIntoRustResult {
type Result;
fn into_rust_result(self) -> Self::Result;
}
impl<T: ::safer_ffi::layout::ReprC> FfiResultIntoRustResult for repr_c::FfiResult<T> {
type Result = Result<T, repr_c::Box<FfiError>>;
fn into_rust_result(self) -> Self::Result {
if let Some(error) = self.error {
Err(error)
} else {
Ok(unsafe {
if ::core::mem::size_of::<T>() > 0 {
::safer_ffi::layout::from_raw_unchecked(self.success)
} else {
::core::mem::transmute_copy(&self.success)
}
})
}
}
}