Skip to content

Commit 767b09b

Browse files
committed
Merge pull request rust-lang#257 from razielgn/patch-1
Fixed type error in read_to_string() example.
2 parents 3397974 + 820ce9e commit 767b09b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

faq.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,14 @@ How do I read a file into a <code>String</code>?
764764
Using the [`read_to_string()`][read__read_to_string] method, which is defined on the [`Read`][Read] trait in [`std::io`][std-io].
765765

766766
```rust
767+
use std::io::Read;
768+
use std::fs::File;
769+
767770
fn read_file(path: &str) -> Result<String, std::io::Error> {
768771
let mut f = try!(File::open(path));
769772
let mut s = String::new();
770773
try!(f.read_to_string(&mut s)); // `s` contains the contents of "foo.txt"
771-
s
774+
Ok(s)
772775
}
773776

774777
fn main() {

0 commit comments

Comments
 (0)