Trait uniffi::LiftReturn

pub unsafe trait LiftReturn<UT>: Sized {
    type ReturnType;

    // 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

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 Types§

type ReturnType

FFI return type for trait interfaces

Required Methods§

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

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

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

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.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

§

impl<K, V, UT> LiftReturn<UT> for HashMap<K, V>
where HashMap<K, V>: Lift<UT>,

§

impl<T, UT> LiftReturn<UT> for Arc<T>
where Arc<T>: Lift<UT>, T: ?Sized,

§

impl<T, UT> LiftReturn<UT> for Vec<T>
where Vec<T>: Lift<UT>,

§

impl<UT> LiftReturn<UT> for bool

§

impl<UT> LiftReturn<UT> for f32

§

impl<UT> LiftReturn<UT> for f64

§

impl<UT> LiftReturn<UT> for i8

§

impl<UT> LiftReturn<UT> for i16

§

impl<UT> LiftReturn<UT> for i32

§

impl<UT> LiftReturn<UT> for i64

§

impl<UT> LiftReturn<UT> for u8

§

impl<UT> LiftReturn<UT> for u16

§

impl<UT> LiftReturn<UT> for u32

§

impl<UT> LiftReturn<UT> for u64

§

impl<UT> LiftReturn<UT> for ()

§

impl<UT> LiftReturn<UT> for String

§

impl<UT> LiftReturn<UT> for SystemTime

Implementors§

§

impl<T, UT> LiftReturn<UT> for Option<T>
where Option<T>: Lift<UT>,

§

type ReturnType = <Option<T> as Lift<UT>>::FfiType

§

impl<UT> LiftReturn<UT> for Duration

§

impl<UT, R, E> LiftReturn<UT> for Result<R, E>
where R: LiftReturn<UT>, E: Lift<UT, FfiType = RustBuffer> + ConvertError<UT>,