To integrate with C code I implement functions with C signature. The C library has an enum with error values and expects that one of them is returned. Like:
Is it possible to map these values to Zig Error values after or with @cinclude? The goal would be to use Zig error handling with try and returning the mapped errors. This would make it way more easy to write Zig functions with C signature and therefore would improve integration with existing C code.
There isn’t any syntax sugar to do this for you, but the mapping is straightforward to do.
However, an error-returning function (!something or !void) cannot be exported to C, because C has no notion of Zig error returns. These functions will simply be returning a MY_LIB_ERROR as a regular return value, so no mapping is needed.
Otherwise, mapping one of these values to Zig, is a straightforward, if verbose switch or table lookup (with the pain of maintenance if the external library is changing).