I'm writing a small library in Rust which is to be consumed by a larger C++ host application. One of the functions written in Rust needs to return a string (UTF-8) value. The size of this response could be arbitrarily large and is not known prior to the call, so preallocating a buffer is not a viable solution.
I'm looking for best practices to ensure that any memory allocated for that string is properly deallocated when the C++ application is done with it.
I'm using cbindgen, but the docs don't seem to address that question. The API surface is small enough that I could manually build headers if that works better.