Should UiStringBuffer be pub?
Don't think it matters in practice, but UiBuffer seems "overly public", specifically:
- The
buffer: Vec<u8>seems like it should be private as someone messing with it directly will surely not be able to do anything good - Should the entire thing be private? It's only used internally, in a private member (
Ui::buffer)
I can answer this actually as the one who wrote it -- yes, it should be public.
So the utility of the contents of the UiBuffer (and it's commensurate safety) exists entirely within individual ImGui calls. Here's that in more detail:
let's say we run ui.text("hello world"). The contents of the global buffer are irrelevant but let's say that it's full of null bytes (just two hundred zeros, vibin it out). We write our text at the end of the buffer (unless it's over a given size, in which case we'll empty it actually). Then, we write in our text. Then, we append a null byte. Then, we had a substring of this byte to DearImgui, which reads that substring up to the null-byte, copying the string to its own storage systems. At that point, it's no longer in our hands -- and the UiBuffer can be immediately erased. Along with that, we return control to the caller.
Therefore, the question isn't really if it should be public (though in general public/private API concerns do matter) it's whether or not the API is unsafe by being public -- it is not.
However, I decided to leave it public because we could easily be making a mistake somehow in that buffer, or a user could want to inspect it, and since they're free to write to it as they wish, and they're also free to depend on imgui_sys if they prefer to make their own abstraction, we might as well leave it public