Linux Format

Develop Linux filesystem tools in Rust

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

You’re reading a preview, subscribe to read more.

More from Linux Format

Linux Format1 min read
Ultimate Desktop Upgrade!
LXF316 will be on sale Tuesday 28th May 2024 Word processors that can help craft that novel you’ve always been talking about and organise large projects. Revive the old roleplaying system for a digital age as we recreate our own play-by-mail gaming
Linux Format4 min read
Linux
The #1 open source mag Future Publishing Limited, Quay House, The Ambury, Bath, BA1 1UA Email contact@linuxformat.com EDITORIAL Editor-in-chief Neil Mohr Art editor Fraser McDermott Production editor Katharine Davies Group editor-in-chief Graham Bar
Linux Format2 min read
Platform Support And Editions
Kali has a huge variety of install options, and these include images for ARM-based computers and pre-made virtual K machine images for most of the popular virtualisers. It’s even possible to install a version of Kali on to an Android-powered device.

Related Books & Audiobooks