# Pre-RFC: write\_str and write\_fmt methods

**URL:** <https://internals.rust-lang.org/t/pre-rfc-write-str-and-write-fmt-methods/1798>\
**Category:** libs\
**Created:** [April 2, 2015, 7:23pm UTC](https://internals.rust-lang.org/t/pre-rfc-write-str-and-write-fmt-methods/1798 "2015-04-02T19:23:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jan\_hudec](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jan_hudec/32/4100_2.png) [@jan\_hudec](https://internals.rust-lang.org/u/jan_hudec)\
**Post date:** [April 2, 2015, 7:23pm UTC](https://internals.rust-lang.org/t/pre-rfc-write-str-and-write-fmt-methods/1798/1 "2015-04-02T19:23:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan\_hudec](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jan_hudec/32/4100_2.png) [@jan\_hudec](https://internals.rust-lang.org/u/jan_hudec)\
**Post date:** [April 2, 2015, 7:28pm UTC](https://internals.rust-lang.org/t/pre-rfc-write-str-and-write-fmt-methods/1798/2 "2015-04-02T19:28:23Z")

</div>

(the other reason would be making work with files with different encoding from utf-8 a bit clearer; I’ve already mentioned [here](http://internals.rust-lang.org/t/pre-rfc-separate-reading-writing-string-from-std-io-read-std-io-write/1642))

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [March 25, 2019, 8:24am UTC](https://internals.rust-lang.org/t/pre-rfc-write-str-and-write-fmt-methods/1798/3 "2019-03-25T08:24:10Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
