Skip to content

file: fix some comments #537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/file/create/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fn main() {
let path = Path::new("out/lorem_ipsum.txt");
let display = path.display();

// Open a file in write-only mode, returns `IoResult<File>`
// Open a file in write-only mode, returns `io::Result<File>`
let mut file = match File::create(&path) {
Err(why) => panic!("couldn't create {}: {}",
display,
Error::description(&why)),
Ok(file) => file,
};

// Write the `LOREM_IPSUM` string to `file`, returns `IoResult<()>`
// Write the `LOREM_IPSUM` string to `file`, returns `io::Result<()>`
match file.write_all(LOREM_IPSUM.as_bytes()) {
Err(why) => {
panic!("couldn't write to {}: {}", display,
Expand Down
2 changes: 1 addition & 1 deletion examples/file/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ The `File` struct represents a file that has been opened (it wraps a file
descriptor), and gives read and/or write access to the underlying file.

Since many things can go wrong when doing file I/O, all the `File` methods
return the `IoResult<T>` type, which is an alias for `Result<T, IoError>`.
return the `io::Result<T>` type, which is an alias for `Result<T, io::Error>`.

This makes the failure of all I/O operations *explicit*. Thanks to this, the
programmer can see all the failure paths, and is encouraged to handle them in
Expand Down
7 changes: 4 additions & 3 deletions examples/file/open/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ fn main() {
let path = Path::new("hello.txt");
let display = path.display();

// Open the path in read-only mode, returns `IoResult<File>`
// Open the path in read-only mode, returns `io::Result<File>`
let mut file = match File::open(&path) {
// The `desc` field of `IoError` is a string that describes the error
// The `description` method of `io::Error` returns a string that
// describes the error
Err(why) => panic!("couldn't open {}: {}", display,
Error::description(&why)),
Ok(file) => file,
};

// Read the file contents into a string, returns `IoResult<String>`
// Read the file contents into a string, returns `io::Result<usize>`
let mut s = String::new();
match file.read_to_string(&mut s) {
Err(why) => panic!("couldn't read {}: {}", display,
Expand Down