Skip to content
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

feat: Adding files exercise #521

Closed
Closed
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
8 changes: 8 additions & 0 deletions exercises/files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Files
The rust standard library supports reading files and writing them directly from the language!

`std::fs::File` is just `A reference to an open file on the filesystem.`

#### Book Sections

- [Reading a file](https://doc.rust-lang.org/stable/book/ch12-02-reading-a-file.html)
21 changes: 21 additions & 0 deletions exercises/files/files1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// files1.rs
// Address all the TODOs to make the tests pass!

// I AM NOT DONE

use std::fs::File;
use std::io::prelude::*;

pub fn create_file() -> std::io::Result<()> {
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!")?;
Ok(())
}



#[test]
fn read_file() {
create_file().unwrap();
//TODO: Read the file created above!
}
8 changes: 7 additions & 1 deletion info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ Very similar to the lines above and below. You've got this!

Step 3:
An iterator goes through all elements in a collection, but what if we've run out of
elements? What should we expect here? If you're stuck, take a look at
elements? What should we expect here? If you're stuck, take a look at
https://doc.rust-lang.org/std/iter/trait.Iterator.html for some ideas.
"""

Expand Down Expand Up @@ -843,3 +843,9 @@ hint = """
The implementation of FromStr should return an Ok with a Person object,
or an Err with a string if the string is not valid.
This is almost like the `try_from_into` exercise."""

[[exercises]]
name = "files"
path = "exercises/files/files1.rs"
mode = "test"
hint = """Take a look at https://doc.rust-lang.org/std/fs/struct.File.html if you are stuck!"""