You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use tabwriter inside an impl of std::fmt::Display, and it seems really complex and inefficient. I'm currently doing it like this. Any suggestions on how to clean things up? Ideally I'd like to just write the table directly to the Formatter.
The text was updated successfully, but these errors were encountered:
Regrettably, I don't see a clean answer here with the current API. The fundamental problem is that a TabWriter is coupled to io::Write---which supports arbitrary bytes---where as the Display infrastructure is a "purer" world that only supports UTF-8.
I guess the ideal API here would permit one to create a TabWriter that wraps a std::fmt::Write instead of a std::io::Write. Then I think you'd just need to do let f = TabWriter::new(f); and then things would be pretty natural from there.
The problem is that TabWriter as it exists today is wedded to std::io::Write.
Probably the right way to do this is to create a TabWriterBuilder that has from_io and from_fmt constructors. They would both produce a TabWriter<W>, but the former would have W: io::Write where as the latter would have W: fmt::Write. The TabWriter would then implement io::Write and fmt::Write itself as appropriate.
Unfortunately, that feels like a "tabwriter 2" kind of thing to me. I personally doubt I'll do that unless I run into the same use case as you. :-)
I'm trying to use tabwriter inside an impl of
std::fmt::Display
, and it seems really complex and inefficient. I'm currently doing it like this. Any suggestions on how to clean things up? Ideally I'd like to just write the table directly to theFormatter
.The text was updated successfully, but these errors were encountered: