Trait uniffi::LiftReturn
pub unsafe trait LiftReturn<UT>: Sized {
type ReturnType;
const TYPE_ID_META: MetadataBuffer;
// Required method
fn try_lift_successful_return(v: Self::ReturnType) -> Result<Self, Error>;
// Provided methods
fn lift_foreign_return(
ffi_return: Self::ReturnType,
call_status: RustCallStatus
) -> Self { ... }
fn lift_error(_buf: RustBuffer) -> Self { ... }
fn handle_callback_unexpected_error(
e: UnexpectedUniFFICallbackError
) -> Self { ... }
}
Expand description
Return foreign values to Rust
This is usually derived from Lower, but we special case types like Result<>
and ()
.
Safety
All traits are unsafe (implementing it requires unsafe impl
) because we can’t guarantee
that it’s safe to pass your type out to foreign-language code and back again. Buggy
implementations of this trait might violate some assumptions made by the generated code,
or might not match with the corresponding code in the generated foreign-language bindings.
These traits should not be used directly, only in generated code, and the generated code should
have fixture tests to test that everything works correctly together.
Required Associated Types§
type ReturnType
type ReturnType
FFI return type for trait interfaces
Required Associated Constants§
const TYPE_ID_META: MetadataBuffer
Required Methods§
fn try_lift_successful_return(v: Self::ReturnType) -> Result<Self, Error>
fn try_lift_successful_return(v: Self::ReturnType) -> Result<Self, Error>
Lift a successfully returned value from a trait interface
Provided Methods§
fn lift_foreign_return(
ffi_return: Self::ReturnType,
call_status: RustCallStatus
) -> Self
fn lift_foreign_return( ffi_return: Self::ReturnType, call_status: RustCallStatus ) -> Self
Lift a foreign returned value from a trait interface
When we call a foreign-implemented trait interface method, we pass a &mut RustCallStatus
and get Self::ReturnType returned. This method takes both of those and lifts Self
from
it.
fn lift_error(_buf: RustBuffer) -> Self
fn lift_error(_buf: RustBuffer) -> Self
Lift a Rust value for a callback interface method error result
This is called for “expected errors” – the callback method returns a Result<> type and the foreign code throws an exception that corresponds to the error type.
fn handle_callback_unexpected_error(e: UnexpectedUniFFICallbackError) -> Self
fn handle_callback_unexpected_error(e: UnexpectedUniFFICallbackError) -> Self
Lift a Rust value for an unexpected callback interface error
The main reason this is called is when the callback interface throws an error type that doesn’t match the Rust trait definition. It’s also called for corner cases, like when the foreign code doesn’t follow the FFI contract.
The default implementation panics unconditionally. Errors used in callback interfaces
handle this using the From<UnexpectedUniFFICallbackError>
impl that the library author
must provide.