9

I was trying to understand what's going on when reading a line, but I couldn't find that there is a method to_string in the documentation for str, even though I know it's there.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
rofrol
  • 14,438
  • 7
  • 79
  • 77
  • I would think that the [ToString](http://doc.rust-lang.org/1.0.0-alpha/std/string/trait.ToString.html) trait should be listed under the Traits of `str`, but (as I'm sure you've noticed) it's not there. I'm not sure if this was a slip, or if the docs are generated automatically and there is a bug in that process. The place *I* learned about it is from [the book](http://doc.rust-lang.org/book/). – Benjamin Lindley Jan 15 '15 at 23:05
  • 8
    There is no direct link between `str` and `ToString::to_string` in the docs -- because `ToString` has a "blanket" implementation "for all T so that T: String" for a different trait, the formatting trait `String`. – bluss Jan 15 '15 at 23:08
  • 1
    @user139873: So it's a documentation generation issue, the documentation would also need to take blanket implementations into account. – Matthieu M. Jan 16 '15 at 07:25
  • 1
    Absolutely. It's always been that the tools don't quite keep up with the language. Eventually it will get there I think. – bluss Jan 17 '15 at 00:22
  • 2
    Note that the `String` trait has been renamed to [`Display`](http://doc.rust-lang.org/std/fmt/trait.Display.html). – Lambda Fairy Feb 14 '15 at 07:59

1 Answers1

3

There is no direct link between &str and ToString::to_string in the docs because ToString has a blanket implementation:

impl<T> ToString for T where T: Display, T: ?Sized

This means that ToString is implemented for any item that implements Display. &str does implement Display.

(Moved from a comment).

Community
  • 1
  • 1
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366