Skip to content

Commit 8347d69

Browse files
committed
I noted tonight that using the examples straight away, e.g. in your main method or in any other method returning a non-std::io::Result value fails, because of reasons mentioned in rust-lang/rfcs#1937.
I suggest uncommenting these parts of the examples, so that the examples are more "copy-pasteable" and show the true requirements for using them. The compilation errors I got wasn't enough to make me realize what the problem was: ``` error[E0277]: the trait bound `std::string::String: std::ops::Try` is not satisfied ``` (Thanks to the helpful people at #rust-beginners who helped me debug it; it was obvious once you knew the prerequisites for using the `?` operator.)
1 parent edd82ee commit 8347d69

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

src/libstd/fs.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ use time::SystemTime;
4141
/// use std::fs::File;
4242
/// use std::io::prelude::*;
4343
///
44-
/// # fn foo() -> std::io::Result<()> {
45-
/// let mut file = File::create("foo.txt")?;
46-
/// file.write_all(b"Hello, world!")?;
47-
/// # Ok(())
48-
/// # }
44+
/// fn foo() -> std::io::Result<()> {
45+
/// let mut file = File::create("foo.txt")?;
46+
/// file.write_all(b"Hello, world!")?;
47+
/// Ok(())
48+
/// }
4949
/// ```
5050
///
5151
/// Read the contents of a file into a [`String`]:
@@ -54,13 +54,13 @@ use time::SystemTime;
5454
/// use std::fs::File;
5555
/// use std::io::prelude::*;
5656
///
57-
/// # fn foo() -> std::io::Result<()> {
58-
/// let mut file = File::open("foo.txt")?;
59-
/// let mut contents = String::new();
60-
/// file.read_to_string(&mut contents)?;
61-
/// assert_eq!(contents, "Hello, world!");
62-
/// # Ok(())
63-
/// # }
57+
/// fn foo() -> std::io::Result<()> {
58+
/// let mut file = File::open("foo.txt")?;
59+
/// let mut contents = String::new();
60+
/// file.read_to_string(&mut contents)?;
61+
/// assert_eq!(contents, "Hello, world!");
62+
/// Ok(())
63+
/// }
6464
/// ```
6565
///
6666
/// It can be more efficient to read the contents of a file with a buffered
@@ -71,14 +71,14 @@ use time::SystemTime;
7171
/// use std::io::BufReader;
7272
/// use std::io::prelude::*;
7373
///
74-
/// # fn foo() -> std::io::Result<()> {
75-
/// let file = File::open("foo.txt")?;
76-
/// let mut buf_reader = BufReader::new(file);
77-
/// let mut contents = String::new();
78-
/// buf_reader.read_to_string(&mut contents)?;
79-
/// assert_eq!(contents, "Hello, world!");
80-
/// # Ok(())
81-
/// # }
74+
/// fn foo() -> std::io::Result<()> {
75+
/// let file = File::open("foo.txt")?;
76+
/// let mut buf_reader = BufReader::new(file);
77+
/// let mut contents = String::new();
78+
/// buf_reader.read_to_string(&mut contents)?;
79+
/// assert_eq!(contents, "Hello, world!");
80+
/// Ok(())
81+
/// }
8282
/// ```
8383
///
8484
/// [`Seek`]: ../io/trait.Seek.html

0 commit comments

Comments
 (0)