I have a cdylib project that generates a dynamic link library to be used in another rust project. When I tried to return a Result type in the export interface, programs just crashed. What I should do if I want to pass enums? Thanks
As implied by the name, cdylib produces a dynamic library conforming to C ABI. Unfortunately, C ABI does not support Result type.
One way to handle enum's through the extern api is to convert them to integers first. See the num crate FromPrimitive and related derive. num::traits::FromPrimitive - Rust
Not sure about option (maybe none will produce null?), but a found a few discussions related to that:
So, as mentioned above, returning -> Result<…, Box<dyn …>> does not work across cdylib boundaries.
To answer the OP question, "how to …", the shortest answer is that you use the types defined in ::abi_stable::std_types::*:
use ::abi_stable::std_types::*; // Naming convention: `RTypeName`.
#[no_mangle] pub extern "C"
fn example () -> RResult<i32, RBoxError>
{
… /* sprinkle `.into()` calls here and there as necessary */
}