Michael-F-Bryan / rust-ffi-guide

A guide for doing FFI using Rust
https://michael-f-bryan.github.io/rust-ffi-guide/
Creative Commons Zero v1.0 Universal
282 stars 18 forks source link

WIP: Error handling #59

Closed Michael-F-Bryan closed 6 years ago

Michael-F-Bryan commented 6 years ago

This adds a chapter on error handling. We're using a mechanism very similar to [libgit2] where any fallible operation will return an "obviously" invalid value (e.g. 0 or null) and set a thread-local variable. This thread-local variable can later be queried by C/C++ to get an error message.

We also talk about exception safety (i.e. wrap everything in panic::catch_unwind()) and using logging as a form of print statements.

(fixes #22)