Part Two
Missed part one? Turn to page 62 to get hold of it!
The subject of this second Rust tutorial is working with files and directories as filesystem entities. This means that we’re going to learn how to move, delete and copy files, explore directories, search directory trees and learn information about file permissions and file metadata. But first, we’re going to learn about the Result data type.
To get started we’re going to look deeper into the Result data type (std::result::Result) that we first saw in last month’s Rust tutorial. Result is a Rust enum. An enum is a type with a list of different predefined values. An enum variable can only have one of these predefined values at any given time. The definition of Result is as follows:
Given that, have in mind that we can change the signature of main() to return a Result value. So, because the Result enum has usually two values, main() can be rewritten to something like the following:
You can replace ParseIntError with any error value you want, including the generic std::io::Error, or you can omit it entirely. You can learn more about Result by visiting https://doc.rust-lang.org/std/result/enum.Result.html.
Rusty Standards
Rust comes with a rich Standard library that can be extended with the use of external libraries, which in Rust terminology are called crates. This section presents the most useful functions and modules