Comment by latch
3 days ago
It wasn't clear from the examples, and the gist doesn't have a `deinit` method, so what happens if an error needs to own data?
> Here, sqlite.ErrorPayload.init saves 500 bytes of error message from sqlite
Who owns those 500 bytes and where are they being freed?
It's just stored as a [256]u8 in the struct.
And what pattern would you recommend if you needed to allocate?
It's worth every effort to avoid situations where a function creates extra clean up responsibilities to the caller only on error conditions.
If I really needed a large error payload, too big to fit on the stack, I'd probably want to do something like this:
The diagnostic struct could contain a caller-provided allocator field which the callee can use, and a deinit() function on the diagnostic struct which frees everything.