0%

Explore various Rust features, data structures, libraries, and toolchain to build modern systems software with the help of hands-on examples

Key Features

  • Learn techniques to design and build system tools and utilities in Rust
  • Explore the different features of the Rust standard library for interacting with operating systems
  • Gain an in-depth understanding of the Rust programming language by writing low-level software

Book Description

Modern programming languages such as Python, JavaScript, and Java have become increasingly accepted for application-level programming, but for systems programming, C and C++ are predominantly used due to the need for low-level control of system resources. Rust promises the best of both worlds: the type safety of Java, and the speed and expressiveness of C++, while also including memory safety without a garbage collector. This book is a comprehensive introduction if you're new to Rust and systems programming and are looking to build reliable and efficient systems software without C or C++.

The book takes a unique approach by starting each topic with Linux kernel concepts and APIs relevant to that topic. You'll also explore how system resources can be controlled from Rust. As you progress, you'll delve into advanced topics. You'll cover network programming, focusing on aspects such as working with low-level network primitives and protocols in Rust, before going on to learn how to use and compile Rust with WebAssembly. Later chapters will take you through practical code examples and projects to help you build on your knowledge.

By the end of this Rust programming book, you will be equipped with practical skills to write systems software tools, libraries, and utilities in Rust.

What you will learn

  • Gain a solid understanding of how system resources are managed
  • Use Rust confidently to control and operate a Linux or Unix system
  • Understand how to write a host of practical systems software tools and utilities
  • Delve into memory management with the memory layout of Rust programs
  • Discover the capabilities and features of the Rust Standard Library
  • Explore external crates to improve productivity for future Rust programming projects

Who this book is for

This book is for developers with basic knowledge of Rust but little to no knowledge or experience of systems programming. System programmers who want to consider Rust as an alternative to C or C++ will also find this book useful.

Table of Contents

  1. Practical System Programming for Rust Developers
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewer
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Reviews
  8. Section 1: Getting Started with System Programming in Rust
  9. Chapter 1: Tools of the Trade – Rust Toolchains and Project Structures
    1. Technical requirements
    2. Choosing the right Rust configuration for your project
    3. Choosing a Rust release channel
    4. Selecting a Rust project type
    5. Introducing Cargo and project structures
    6. Automating build management with Cargo
    7. Building a basic binary crate
    8. Configuring Cargo
    9. Building a static library crate
    10. Automating dependency management
    11. Specifying the location of a dependency
    12. Using dependent packages in source code
    13. Writing and running automated tests
    14. Writing unit tests in Rust
    15. Writing integration tests in Rust
    16. Controlling test execution
    17. Running tests sequentially or in parallel
    18. Documenting your project
    19. Writing inline documentation comments within crate
    20. Writing documentation in markdown files
    21. Running documentation tests
    22. Summary
    23. Further reading
  10. Chapter 2: A Tour of the Rust Programming Language
    1. Technical requirements
    2. Analyzing the problem domain
    3. Modeling the system behavior
    4. Building the tokenizer
    5. Tokenizer data structure
    6. Tokenizer data processing
    7. Building the parser
    8. Parser data structure
    9. Parser methods
    10. Operator precedence
    11. Building the evaluator
    12. Dealing with errors
    13. Putting it all together
    14. Summary
  11. Chapter 3: Introduction to the Rust Standard Library
    1. Technical requirements
    2. The Rust Standard Library and systems programming
    3. Exploring the Rust Standard Library
    4. Computation-oriented modules
    5. Syscalls-oriented modules
    6. Building a template engine
    7. Template syntax and design
    8. Writing the template engine
    9. Executing the template engine
    10. Summary
    11. Further reading
  12. Chapter 4: Managing Environment, Command Line, and Time
    1. Technical requirements
    2. Project scope and design overview
    3. What will we build?
    4. Technical design
    5. Using the Rust Standard Library
    6. Coding the imagix library
    7. Developing the command-line application and testing
    8. Designing the command-line interface
    9. Coding the command-line binary using structopt
    10. Summary
  13. Section 2: Managing and Controlling System Resources in Rust
  14. Chapter 5: Memory Management in Rust
    1. Technical requirements
    2. The basics of OS memory management
    3. The memory management lifecycle
    4. The process memory layout
    5. Understanding the memory layout of Rust programs
    6. Rust program memory layout
    7. The characteristics of stack, heap, and static memory
    8. The Rust memory management lifecycle
    9. Overview of the Rust memory management lifecycle
    10. Memory allocation
    11. Memory use and manipulation
    12. Memory deallocation
    13. Implementing a dynamic data structure
    14. Changes to the design of the template engine
    15. Coding the dynamic data structure
    16. Summary
    17. Further reading
  15. Chapter 6: Working with Files and Directories in Rust
    1. Technical requirements
    2. Understanding Linux system calls for file operations
    3. Doing file I/O in Rust
    4. Learning directory and path operations
    5. Setting hard links, symbolic links, and performing queries
    6. Writing a shell command in Rust (project)
    7. Code overview
    8. Error handling
    9. Source metric computation
    10. The main() function
    11. Summary
  16. Chapter 7: Implementing Terminal I/O in Rust
    1. Technical requirements
    2. Introducing terminal I/O fundamentals
    3. Characteristics of terminals
    4. The Termion crate
    5. What will we build?
    6. Working with the terminal UI (size, color, styles) and cursors
    7. Writing data structures and the main() function
    8. Initializing the text viewer and getting the terminal size
    9. Displaying a document and styling the terminal color, styles, and cursor position
    10. Exiting the text viewer
    11. Processing keyboard inputs and scrolling
    12. Listening to keystrokes from the user
    13. Positioning the terminal cursor
    14. Enabling scrolling on the terminal
    15. Processing mouse inputs
    16. Summary
  17. Chapter 8: Working with Processes and Signals
    1. Technical requirements
    2. Understanding Linux process concepts and syscalls
    3. How does a program become a process?
    4. Delving into Linux process fundamentals
    5. Spawning processes with Rust
    6. Spawning new child processes
    7. Terminating processes
    8. Checking the status of a child process' execution
    9. Handling I/O and environment variables
    10. Handling the I/O of child processes
    11. Setting the environment for the child process
    12. Handling panic, errors, and signals
    13. Aborting the current process
    14. Signal handling
    15. Writing a shell program in Rust (project)
    16. Summary
  18. Chapter 9: Managing Concurrency
    1. Technical requirements
    2. Reviewing concurrency basics
    3. Concurrency versus parallelism
    4. Concepts of multi-threading
    5. Spawning and configuring threads
    6. Error handling in threads
    7. Message passing between threads
    8. Achieving concurrency with shared state
    9. Defining the program structure
    10. Aggregating source file statistics in shared state
    11. Pausing thread execution with timers
    12. Summary
  19. Section 3: Advanced Topics
  20. Chapter 10: Working with Device I/O
    1. Technical requirements
    2. Understanding device I/O fundamentals in Linux
    3. What are device drivers?
    4. Types of devices
    5. Doing buffered reads and writes
    6. Working with standard input and output
    7. Chaining and iterators over I/O
    8. Handling errors and returning values
    9. Getting details of connected USB devices (project)
    10. Designing the project
    11. Writing data structures and utility functions
    12. Writing the main() function
    13. Summary
  21. Chapter 11: Learning Network Programming
    1. Technical requirements
    2. Reviewing networking basics in Linux
    3. Understanding networking primitives in the Rust standard library
    4. Programming with TCP and UDP in Rust
    5. Writing a UDP server and client
    6. Writing a TCP server and client
    7. Writing a TCP reverse proxy (project)
    8. Writing the origin server – structs and methods
    9. Writing the origin server – the main() function
    10. Writing the reverse proxy server
    11. Summary
  22. Chapter 12: Writing Unsafe Rust and FFI
    1. Technical requirements
    2. Introducing unsafe Rust
    3. How do you distinguish between safe and unsafe Rust code?
    4. Operations in unsafe Rust
    5. Introducing FFIs
    6. Reviewing guidelines for safe FFIs
    7. Calling Rust from C (project)
    8. Understanding the ABI
    9. Summary
  23. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
18.217.84.171