uniffi

Trait LiftReturn

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

Required Methods§

Source

fn lift_callback_return(buf: RustBuffer) -> Self

Lift a Rust value for a callback interface method result

Provided Methods§

Source

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.

Source

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.

Implementations on Foreign Types§

Source§

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

Source§

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

Source§

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

Source§

impl<UT> LiftReturn<UT> for bool

Source§

impl<UT> LiftReturn<UT> for f32

Source§

impl<UT> LiftReturn<UT> for f64

Source§

impl<UT> LiftReturn<UT> for i8

Source§

impl<UT> LiftReturn<UT> for i16

Source§

impl<UT> LiftReturn<UT> for i32

Source§

impl<UT> LiftReturn<UT> for i64

Source§

impl<UT> LiftReturn<UT> for u8

Source§

impl<UT> LiftReturn<UT> for u16

Source§

impl<UT> LiftReturn<UT> for u32

Source§

impl<UT> LiftReturn<UT> for u64

Source§

impl<UT> LiftReturn<UT> for ()

Source§

impl<UT> LiftReturn<UT> for String

Source§

impl<UT> LiftReturn<UT> for SystemTime

Implementors§