# Add an easier way to append \`T: Display\` to \`String\` to stdlib?

**URL:** <https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607>\
**Category:** libs\
**Created:** [July 20, 2019, 1:25pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607 "2019-07-20T13:25:45Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Boomshroom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/boomshroom/32/5932_2.png) [@Boomshroom](https://internals.rust-lang.org/u/Boomshroom)\
**Post date:** [July 26, 2019, 8:56pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/21 "2019-07-26T20:56:41Z")

</div>

> A collection of methods that are required to format a message into a stream.
> 
> This trait is the type which this modules requires when formatting information. **This is similar to the standard library's io::Write trait, but it is only intended for use in libcore.**
> 
> This trait should generally not be implemented by consumers of the standard library. The write! macro accepts an instance of io::Write, and **the io::Write trait is favored over implementing this trait.**

It seems the main reason `fmt::Write` exists at all is just because `core::io` stubbornly refuses to exist. Why doesn't it again? Aside from adding `io` to `core`, one possible solution to the `Write` ambiguity would be to have `Error` be an associated type to `fmt::Result`. For `String`, `Error` would be `!`, and `io::Write` could be aliased to `fmt::Write<Error=io::Error>`.

I would absolutely love to be able to use `write!()` without importing. Heck, would it possible for `core::write!()` itself to `use core::fmt::Write;` and `std::write!()` to `use std::io::Write;`?

If `core::io` was a thing, then `fmt::Write` could just be deleted entirely, or simply deprecated for backwards compatibility.

---

<div class="post-metadata">

**Author:** ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)\
**Post date:** [July 26, 2019, 9:03pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/22 "2019-07-26T21:03:33Z")

</div>

> [@Boomshroom](#):
>
> If `core::io` was a thing, then `fmt::Write` could just be deleted entirely, or simply deprecated for backwards compatibility.

`io::Write` can't be implemented for `String` because it can be used to write arbitrary bytes.

---

<div class="post-metadata">

**Author:** ![MikailBag](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mikailbag/32/5376_2.png) [@MikailBag](https://internals.rust-lang.org/u/MikailBag)\
**Post date:** [July 29, 2019, 4:51pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/23 "2019-07-29T16:51:51Z")

</div>

io::Write String can return "invalid data" error if buf given is not utf8

---

<div class="post-metadata">

**Author:** ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)\
**Post date:** [July 29, 2019, 4:58pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/24 "2019-07-29T16:58:59Z")

</div>

But what if somebody calls `write_all` with input that ends in the middle of a character?

---

<div class="post-metadata">

**Author:** ![MikailBag](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mikailbag/32/5376_2.png) [@MikailBag](https://internals.rust-lang.org/u/MikailBag)\
**Post date:** [July 29, 2019, 5:20pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/25 "2019-07-29T17:20:04Z")

</div>

I think error should be returned. This behavior would be enough for format! needs, to my mind.

---

<div class="post-metadata">

**Author:** ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)\
**Post date:** [July 29, 2019, 6:32pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/26 "2019-07-29T18:32:59Z")

</div>

But splitting up a write into multiple calls should not change the results. Otherwise, something like `BufWriter` could not exist.

---

<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:** [October 27, 2019, 6:48pm UTC](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607/27 "2019-10-27T18:48:23Z")

</div>

Closed on October 27, 2019, 6:48pm UTC

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

[Previous page](https://internals.rust-lang.org/t/add-an-easier-way-to-append-t-display-to-string-to-stdlib/10607.md?page=1)
