How it works...
After setting up the project, we dive right in with step 1 and provide the imports required to work with the file APIs. Note that working with and reading/writing files are in two different modules: std::fs for access and std::io for read and write. In addition to that, the std::path module provides powerful and easy ways to work with paths in a platform-agnostic way.
Step 2 provides a function that shows several ways to read data from the test file we created in preparation. First, we open the file and pass the reference to BufReader (https://doc.rust-lang.org/std/io/struct.BufReader.html), a buffered reader. While the initial reference allows reading data as well, BufReader reads the file contents in bulk and serves them ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access