Trait uniffi::LowerReturn

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

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

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.

Implementations on Foreign Types§

§

impl<UT> LowerReturn<UT> for u32

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for i32

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for String

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for ()

§

type ReturnType = ()

§

fn lower_return( _: () ) -> Result<<() as LowerReturn<UT>>::ReturnType, RustBuffer>

§

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

§

impl<UT> LowerReturn<UT> for SystemTime

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for f64

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for i64

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for u64

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for i16

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for f32

§

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

§

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

§

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

§

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>

§

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

§

impl<UT> LowerReturn<UT> for u8

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for bool

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for u16

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for i8

§

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

§

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

§

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

Implementors§

§

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

§

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

§

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

§

impl<UT> LowerReturn<UT> for Duration

§

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

§

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

§

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

§

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

§

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