title: Why doesn't Read::read_to_string() return the string?
body: <p>In the <a href="https://doc.rust-lang.org/std/io/trait.Read.html" rel="noreferrer"><code>Read</code> trait</a>, many functions/methods take a <code>buf: &amp;mut XXX</code> as (one of the) parameter(s) and return <code>Result&lt;usize&gt;</code>. For example, <a href="https://doc.rust-lang.org/std/io/trait.Read.html#method.read_to_string" rel="noreferrer"><code>read_to_string()</code></a> takes <code>buf: &amp;mut String</code> as one of the parameters and returns <code>Result&lt;usize&gt;</code>.</p>
  
  <p>As I came from many languages, the so-called <em>modern</em> ones usually return the string for a <code>read_string()</code> function call. The design of the <code>Read</code> trait in Rust kind of shocks me because it doesn't <strong>return</strong> the string, but rather <strong>passes it as a parameter</strong> (similar to C or other more primitive languages).</p>
  
  <p>I'm aware the return value (<code>Result</code>) is used to indicate whether the read succeeded or not, and it can be passed to <code>match</code> expressions. (I've learned Lisp and Go previously, so I'm not questioning this kind of design.)</p>
  
  <p>Why didn't the core developers design this trait as "returning the string together with the error message"?</p>
  
  <p>For example, why not design it like this:</p>
  
  <pre><code>fn read(&amp;mut self) -&gt; Result&lt;String&gt; { ... }
  </code></pre>
  
  <p>The <code>String</code> also contains the length, so the user can access the length by calling <code>.len()</code> when needed. The user can concatenate it to any other <code>String</code> if (s)he wishes, but the key point is that there is no need to create / have one before calling this function.</p>
  
  <p>Is there any particular reasons to design this trait like what it is now?</p>
  
  <p>p.s. I'm still learning Rust (by following <a href="https://doc.rust-lang.org/book/" rel="noreferrer"><em>The Rust Programming Language</em></a>), and am reading the second edition after reading most of the first edition. Please correct me if the code above contains any errors (especially when dealing with lifetimes).</p>