Trait uniffi::LiftReturn

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

    const TYPE_ID_META: MetadataBuffer;

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

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 Associated Constants§

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.

Implementations on Foreign Types§

§

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

§

type ReturnType = <Vec<T, Global> as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <Vec<T, Global> as LiftReturn<UT>>::ReturnType ) -> Result<Vec<T, Global>, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for bool

§

type ReturnType = <bool as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <bool as LiftReturn<UT>>::ReturnType ) -> Result<bool, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for f64

§

type ReturnType = <f64 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <f64 as LiftReturn<UT>>::ReturnType ) -> Result<f64, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for ()

§

type ReturnType = ()

§

fn try_lift_successful_return(_: ()) -> Result<(), Error>

§

const TYPE_ID_META: MetadataBuffer = MetadataBuffer::from_code(metadata::codes::TYPE_UNIT)

§

impl<UT> LiftReturn<UT> for i64

§

type ReturnType = <i64 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <i64 as LiftReturn<UT>>::ReturnType ) -> Result<i64, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for i16

§

type ReturnType = <i16 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <i16 as LiftReturn<UT>>::ReturnType ) -> Result<i16, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for u64

§

type ReturnType = <u64 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <u64 as LiftReturn<UT>>::ReturnType ) -> Result<u64, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for String

§

type ReturnType = <String as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <String as LiftReturn<UT>>::ReturnType ) -> Result<String, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for f32

§

type ReturnType = <f32 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <f32 as LiftReturn<UT>>::ReturnType ) -> Result<f32, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for u8

§

type ReturnType = <u8 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <u8 as LiftReturn<UT>>::ReturnType ) -> Result<u8, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for i8

§

type ReturnType = <i8 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <i8 as LiftReturn<UT>>::ReturnType ) -> Result<i8, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for u32

§

type ReturnType = <u32 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <u32 as LiftReturn<UT>>::ReturnType ) -> Result<u32, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for i32

§

type ReturnType = <i32 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <i32 as LiftReturn<UT>>::ReturnType ) -> Result<i32, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for SystemTime

§

type ReturnType = <SystemTime as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <SystemTime as LiftReturn<UT>>::ReturnType ) -> Result<SystemTime, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

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

§

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

§

fn try_lift_successful_return( v: <Arc<T> as LiftReturn<UT>>::ReturnType ) -> Result<Arc<T>, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for u16

§

type ReturnType = <u16 as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <u16 as LiftReturn<UT>>::ReturnType ) -> Result<u16, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

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

§

type ReturnType = <HashMap<K, V, RandomState> as Lift<UT>>::FfiType

§

fn try_lift_successful_return( v: <HashMap<K, V, RandomState> as LiftReturn<UT>>::ReturnType ) -> Result<HashMap<K, V, RandomState>, Error>

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

Implementors§

§

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

§

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

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

impl<UT> LiftReturn<UT> for Duration

§

type ReturnType = <Duration as Lift<UT>>::FfiType

§

const TYPE_ID_META: MetadataBuffer = <Self as crate::Lift::<UT>>::TYPE_ID_META

§

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

§

type ReturnType = <R as LiftReturn<UT>>::ReturnType

§

const TYPE_ID_META: MetadataBuffer = MetadataBuffer::from_code(metadata::codes::TYPE_RESULT).concat(R::TYPE_ID_META).concat(E::TYPE_ID_META)