So why not ask for that? It makes total sense to specifically promise that (especially since it falls under observable behavior and the "it just does w.write_fmt
" that is relied upon and (mostly) guaranteed. This would be a simple docs PR with an FCP, then merged, probably resolved faster than this thread, and definitely faster than any extensions to the Write
interface.
If this is guaranteed (which, depending on consensus, it might already effectively be!), then you have two clean options to interface with your sink:
- Have users use
write!
for each unit chunk pushed to your sink. I think this is fair enough, especially if you want to preserve internal newlines.
- Have users use
writeln!
, and buffer writes, which you then pass along to your log backend after splitting on newlines.
It's not like fmt::Arguments
gives you any introspection power anyway, so you eventually have to dump it into a string (or another write sink, I suppose, which probably still internally uses a string buffer for a format call anyway) one way or another. It barely costs you anything to then check for a trailing newline then (what a write_fmt_line
would eliminate checking). Even scanning and splitting on newline characters is probably dwarfed in cost by the actual formatting and writing.
There are existing ways to accomplish what you've communicated you want, that work quite well already. What you're proposing is that the language is changed impacting everyone else to marginally improve (if at all) one edge case you're dealing with, and insisting it be done the way you are proposing it should be done, and just dismissing proposed alternatives as missing the point.
I hope you can see how this negatively reflects back on the proposals you put forward. You may not intend to be, but it reads as standoffish (or even bad faith, depending on how (un)charitable the reader is feeling) on our side of the screen, as we lack the context that you have.
And just in general, I also would like to see the formatting machinery more thoroughly documented and specified. Some Write
sinks should probably guarantee being zero-(extra)-copy, in that they don't use an internal buffer and just write
each fragment written by fmt
calls. Maybe more sinks should provide an inherent write_fmt
so you don't have to import Write
to write to them. Perhaps the implementation could be improved or made more configurable, or more could be exposed to the consumer so they have more ways to implement write_fmt
than just dumping to another sink. The most meaningful small improvement I can think of would actually be documenting if fmt_arguments.fmt(w)
is guaranteed to be equivalent to w.write_fmt(fmt_arguments)
(modulo requisite (re)borrowing), or just that it writes the same content.
But all of this can (and should) be done without breaking the public API.