Doing file I/O in Rust
In this section, we will look at the Rust method calls that let us work with files in Rust programs. The Rust Standard Library spares the programmer from having to work with system calls directly and provides a set of wrapper methods exposing APIs for common file operations.
The primary module in the Rust Standard Library for working with files is std::fs
. The official documentation for std::fs
can be found here: https://doc.rust-lang.org/std/fs/index.html. This documentation provides the set of methods, structs, enums, and traits that collectively provide features for working with files. It helps to study the structure of the std::fs
module to gain a deeper understanding. However, for those starting out with exploring system programming in Rust, it is more useful to begin with a mental model of what kinds of things a programmer would like to do with files, and map it back to the Rust Standard Library. This is what we will do in this section. The common lifecycle...