pub unsafe trait LiftReturn<UT>: Sized {
const TYPE_ID_META: MetadataBuffer;
// Required method
fn lift_callback_return(buf: RustBuffer) -> Self;
// Provided methods
fn lift_callback_error(_buf: RustBuffer) -> Self { ... }
fn handle_callback_unexpected_error(
e: UnexpectedUniFFICallbackError,
) -> Self { ... }
}
Expand description
Reexport items from other uniffi creates 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 Constants§
const TYPE_ID_META: MetadataBuffer
Required Methods§
Sourcefn lift_callback_return(buf: RustBuffer) -> Self
fn lift_callback_return(buf: RustBuffer) -> Self
Lift a Rust value for a callback interface method result
Provided Methods§
Sourcefn lift_callback_error(_buf: RustBuffer) -> Self
fn lift_callback_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.
Sourcefn 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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.