Chapter 6: Working with Files and Directories in Rust
In the previous chapter, we looked at the details of how Rust uses memory, a key system resource.
In this chapter, we will look at how Rust interacts with another important class of system resources – files and directories. The Rust Standard Library offers a rich set of abstractions that enable platform-independent file and directory operations.
For this chapter, we will review the basics of how files are managed by Unix/Linux, and master the key APIs that the Rust Standard Library provides to deal with files, paths, links, and directories.
Using the Rust Standard Library, we will implement a shell command, rstat
, that counts the total number of lines of Rust code in a directory (and its subfolders), and provides a few additional source code metrics.
We will cover the topics in the following order:
- Understanding Linux system calls for file operations
- Doing file I/O in Rust
- Learning directory and...