// FfiConverters for "flat errors" // // These are errors where we only lower the to_string() value, rather than any associated data. // We lower the to_string() value unconditionally, whether the enum has associated data or not. fn flat_error_ffi_converter_impl(item: &EnumItem, options: &DeriveOptions) -> TokenStream { let name = item.name(); let ident = item.ident(); let lower_impl_spec = options.ffi_impl_header("Lower", ident); let lift_impl_spec = options.ffi_impl_header("Lift", ident); let type_id_impl_spec = options.ffi_impl_header("TypeId", ident); let derive_ffi_traits = options.derive_ffi_traits(ident, &["LowerError", "ConvertError"]); let mod_path = match mod_path() {
Ok(p) => p,
Err(e) => return e.into_compile_error(),
};
let lower_impl = { letmut match_arms: Vec<_> = item
.enum_()
.variants
.iter()
.enumerate()
.map(|(i, v)| { let v_ident = &v.ident; let idx = Index::from(i + 1); let write_string = ffiops::write(quote! { ::std::string::String });
let lift_impl = if item.generate_error_try_read() { let match_arms = item.enum_().variants.iter().enumerate().map(|(i, v)| { let v_ident = &v.ident; let idx = Index::from(i + 1);
fn try_lift(v: ::uniffi::RustBuffer) -> ::uniffi::deps::anyhow::Result<Self> { #try_lift(v)
}
}
}
} else {
quote! { // Lifting flat errors is not currently supported, but we still define the trait so // that dicts containing flat errors don't cause compile errors (see ReturnOnlyDict in // coverall.rs). // // Note: it would be better to not derive `Lift` for dictionaries containing flat // errors, but getting the trait bounds and derived impls there would be much harder. // For now, we just fail at runtime. #[automatically_derived] unsafe#lift_impl_spec { type FfiType = ::uniffi::RustBuffer;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.