Trait uniffi::LowerReturn

source ·
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

Reexport items from other uniffi creates 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§

source

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§

Required Methods§

source

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§

source

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl<K, V, UT> LowerReturn<UT> for HashMap<K, V>
where HashMap<K, V>: Lower<UT>,

source§

impl<T, UT> LowerReturn<UT> for Arc<T>
where Arc<T>: Lower<UT>, T: ?Sized,

source§

impl<T, UT> LowerReturn<UT> for Vec<T>
where Vec<T>: Lower<UT>,

source§

impl<UT> LowerReturn<UT> for bool

source§

impl<UT> LowerReturn<UT> for f32

source§

impl<UT> LowerReturn<UT> for f64

source§

impl<UT> LowerReturn<UT> for i8

source§

impl<UT> LowerReturn<UT> for i16

source§

impl<UT> LowerReturn<UT> for i32

source§

impl<UT> LowerReturn<UT> for i64

source§

impl<UT> LowerReturn<UT> for u8

source§

impl<UT> LowerReturn<UT> for u16

source§

impl<UT> LowerReturn<UT> for u32

source§

impl<UT> LowerReturn<UT> for u64

source§

impl<UT> LowerReturn<UT> for ()

source§

impl<UT> LowerReturn<UT> for String

source§

impl<UT> LowerReturn<UT> for SystemTime

Implementors§

source§

impl<T, UT> LowerReturn<UT> for Option<T>
where Option<T>: Lower<UT>,

source§

impl<UT> LowerReturn<UT> for Duration

source§

impl<UT, R, E> LowerReturn<UT> for Result<R, E>
where R: LowerReturn<UT>, E: Lower<UT> + Error + Send + Sync + 'static,