Pre-RFC: write_str and write_fmt methods


#1

There are two things that have write_fmt method:

  • std::fmt::Write (=core::fmt::Write)
  • std::io::Write

and three things that have write_str method. The above two plus

  • std::fmt::Formatter

I understand that the formatting macros don’t care, because they just expand to call to write_fmt and don’t care about which trait provides the method.

However for functions that want to take “something to which I can format” this situation is bad, because streams implement std::io::Write, but std::string::String implements std::fmt::Write.

It would be much more useful if there was only one trait for writing string (std::fmt::Write) and another for writing bytes (std::io::Write). And the streams in std::io would then define both. Or even only stdin/stdout/stderr would and files would require wrapping to be explicit about encoding.


#2

(the other reason would be making work with files with different encoding from utf-8 a bit clearer; I’ve already mentioned here)