A C api for the amazing codespan Rust crate.
Most of the important features are implemented. Full style custimzation is not implemented yet.
The full api is defined in this header file. It is very verbose and should be self explanatory; however, pay special attention to these:
- Memory Management
Objects allocated by
codespan_new_source_mapandcodespan_new_diagnosticmust be be deallocated bycodespan_delete_source_mapandcodespan_delete_diagnostic. - Character Encoding
All pointers to text buffers should point to valid UTF-8 encoded data. Pointers to text buffers passed to callbacks will always point to valid UTF-8 encoded data.
- CodespanSourceMap Callbacks
The CodespanSourceMap struct is intialized with various callbacks corresponding to the methods defined in the Files trait. Just like in the trait, the
line_numberandline_columncallbacks are optional and can be null. Make sure to uphold any requirements described in their documentation, else you may introduce undefined behavior. Do any error checking required outside these callbacks before callingcodespan_write_diagnostic.Text buffers returned by these callbacks are not copied internally. The callbacks are triggered when calling
codespan_write_diagnostic, so any memory returned needs to be valid until this function returns.
You will need a rust toolchain installed to build.
cargo build --release
The dynamic library will be placed under ./target/release/