Trait uniffi::LowerReturn
pub unsafe trait LowerReturn<UT>: Sized {
type ReturnType: FfiDefault;
const TYPE_ID_META: MetadataBuffer;
// Required method
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustBuffer>;
// Provided method
fn handle_failed_lift(arg_name: &str, e: Error) -> Self { ... }
}
Expand description
Return Rust values to the foreign code
This is usually derived from Lift, 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: FfiDefault
type ReturnType: FfiDefault
The type that should be returned by scaffolding functions for this type.
When derived, it’s the same as FfiType
.
Required Associated Constants§
const TYPE_ID_META: MetadataBuffer
Required Methods§
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustBuffer>
fn lower_return(obj: Self) -> Result<Self::ReturnType, RustBuffer>
Lower this value for scaffolding function return
This method converts values into the Result<>
type that [rust_call] expects. For
successful calls, return Ok(lower_return)
. For errors that should be translated into
thrown exceptions on the foreign code, serialize the error into a RustBuffer and return
Err(buf)
Provided Methods§
fn handle_failed_lift(arg_name: &str, e: Error) -> Self
fn handle_failed_lift(arg_name: &str, e: Error) -> Self
If possible, get a serialized error for failed argument lifts
By default, we just panic and let rust_call
handle things. However, for Result<_, E>
returns, if the anyhow error can be downcast to E
, then serialize that and return it.
This results in the foreign code throwing a “normal” exception, rather than an unexpected
exception.