Trait uniffi::LowerReturn

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

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

type ReturnType: FfiDefault

The type that should be returned by scaffolding functions for this type.

When derived, it’s the same as FfiType.

Required Methods§

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

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§

§

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

§

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

§

fn lower_return( obj: HashMap<K, V> ) -> Result<<HashMap<K, V> as LowerReturn<UT>>::ReturnType, RustBuffer>

§

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

§

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

§

fn lower_return( obj: Arc<T> ) -> Result<<Arc<T> as LowerReturn<UT>>::ReturnType, RustBuffer>

§

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

§

type ReturnType = <Vec<T> as Lower<UT>>::FfiType

§

fn lower_return( obj: Vec<T> ) -> Result<<Vec<T> as LowerReturn<UT>>::ReturnType, RustBuffer>

§

impl<UT> LowerReturn<UT> for bool

§

impl<UT> LowerReturn<UT> for f32

§

impl<UT> LowerReturn<UT> for f64

§

impl<UT> LowerReturn<UT> for i8

§

impl<UT> LowerReturn<UT> for i16

§

impl<UT> LowerReturn<UT> for i32

§

impl<UT> LowerReturn<UT> for i64

§

impl<UT> LowerReturn<UT> for u8

§

impl<UT> LowerReturn<UT> for u16

§

impl<UT> LowerReturn<UT> for u32

§

impl<UT> LowerReturn<UT> for u64

§

impl<UT> LowerReturn<UT> for ()

§

impl<UT> LowerReturn<UT> for String

§

impl<UT> LowerReturn<UT> for SystemTime

Implementors§

§

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

§

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

§

impl<UT> LowerReturn<UT> for Duration

§

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