If the user's cxx::bridge invocation includes any header that defines
the following function, they get it's behavior as the exception-to-Result
conversion.
namespace rust::behavior {
template <typename Try, typename Fail>
static void trycatch(Try &&func, Fail &&fail) noexcept try {
func();
} catch (/* up to you */) {
fail(/* const char *msg */);
}
}
The default behavior is equivalent to:
} catch (const std::exception &e) {
fail(e.what());
}
Codebases that use Folly, for example, may be interested in behavior
like this instead for better type information on the error messages:
} catch (const std::exception &e) {
fail(folly::exceptionStr(e));
} catch (...) {
fail("<unknown exception>");
}
Not currently usable as a function argument or explicit return value,
but will be required when we introduce Result for the case of fallible
void functions, whose return type will be Result<()>.
https://doc.rust-lang.org/std/boxed/index.html:
So long as T: Sized, a Box<T> is guaranteed to be represented as a
single pointer and is also ABI-compatible with C pointers (i.e. the C
type T*).
Clang-format doesn't always like the same ending comment as the start of
the block. In particular it wants:
inline namespace cxxbridge01 {
...
} // namespace cxxbridge01
This avoids collision with the user's namespaces having the same name.
Less important in the context of the current names right now, but more
important after we move our public C++ API from cxxbridge:: to rust::.
In fact our example code already uses org::rust:: as the namespace,
inside of which a non-absolute rust:: would cause trouble.