I am working on a library that is written in Rust.
The user of this library uses C++ instead of Rust,
so the public interfaces are all extern "C"
functions in Rust.
There are many C APIs in this library, over 100 APIs.
About 1000 lines of code needed to write a test application,
to make use of all of those APIs in the library.
Any suggestion how to write the test application?
- Use Rust language using the C APIs, but it is painful to have "unsafe" everywhere
- Use the corresponding Rust APIs for C API, but limits the code coverage for C API.
- Write the test program in C++, but I prefer pure Rust, and mixing build of Rust and C++ needs some work.
- Implement a safe Rust wrappper on top of C API. This ensure C API are tested, but there are too many boilterplate code.
The C API is designed in object oriented style
For example, some APIs are (simplied here):
typedef struct Version {
int64_t handle;
} Version;
error_code_t VersionGetCString(Version version, const char** cstring);
error_code_t VersionGetCommitHash(Version version, const char** commitHash);
The corresponding Rust code is similar to
struct Version {
cstring: &CStr,
commitHash: &CStr,
}
// extern "C" functions omitted