dtolnay / cxx

Safe interop between Rust and C++
https://cxx.rs
Apache License 2.0
5.79k stars 325 forks source link

`Result` Thoughts about Leaf / Outcome & PR0709 #16

Open GregBowyer opened 4 years ago

GregBowyer commented 4 years ago

Hi there, this library looks interesting.

I was wondering if you had any thoughts on "converting" simple rust errors (say of the ErrKind flavor) into boilerplated errors from one of the following C++ libraries:

dtolnay commented 4 years ago

This isn't something I plan to tackle in the near term, but I do have some loose plans for how we will expose customization of the mapping between the languages. Codebases that use the different error approaches from your links, or that use exceptions, will want a Rust Result value to turn into somewhat different code coming out of our C++ code generator. Relatedly, codebases that use a nonstandard string type will want some way to get smooth interop with that on the Rust side.

There is more design work to do, but I'd like for this stuff to not be built as special cases in this project. Instead such customization would be exposed in a sort of plugin mechanism where the codegen behavior is defined by a Rust procedural macro or something like that, and all our native types for which we ship support out of the box would be implemented through that same mechanism.

Then for something like Leaf/Outcome it would be a matter of someone writing the procedural macro that implements the understanding of how to operate on those types, putting it on crates.io, and then we register the dependency in Cargo.toml and use its types in our FFI signatures.