Book Image

Rust Programming Cookbook

By : Claus Matzinger
Book Image

Rust Programming Cookbook

By: Claus Matzinger

Overview of this book

Rust 2018, Rust's first major milestone since version 1.0, brings more advancement in the Rust language. The Rust Programming Cookbook is a practical guide to help you overcome challenges when writing Rust code. This Rust book covers recipes for configuring Rust for different environments and architectural designs, and provides solutions to practical problems. It will also take you through Rust's core concepts, enabling you to create efficient, high-performance applications that use features such as zero-cost abstractions and improved memory management. As you progress, you'll delve into more advanced topics, including channels and actors, for building scalable, production-grade applications, and even get to grips with error handling, macros, and modularization to write maintainable code. You will then learn how to overcome common roadblocks when using Rust for systems programming, IoT, web development, and network programming. Finally, you'll discover what Rust 2018 has to offer for embedded programmers. By the end of the book, you'll have learned how to build fast and safe applications and services using Rust.
Table of Contents (12 chapters)

To get the most out of this book

We consider a few things in terms of programming fundamentals and we assume that you are familiar with these concepts already. Here is a list of terms you should be able to explain in a programming context:

  • Types and enums
  • Control statements and execution flow
  • Program architectures and patterns
  • Streams and iterators
  • Linking
  • Generics

Equipped with this knowledge, you can dive in with an editor of your choice (we recommend Visual Studio Code (https://code.visualstudio.com), together with the official Rust extension (https://marketplace.visualstudio.com/items?itemName=rust-lang.rust)). While Rust is a cross-platform programming language, some recipes are significantly easier on Linux or macOS. Windows users are encouraged to use the Windows Subsystem for Linux (https://docs.microsoft.com/en-us/windows/wsl/install-win10) for a better experience.

Download the example code files

You can download the example code files for this book from your account at www.packt.com. If you purchased this book elsewhere, you can visit www.packtpub.com/support and register to have the files emailed directly to you.

You can download the code files by following these steps:

  1. Log in or register at www.packt.com.
  2. Select the Support tab.
  3. Click on Code Downloads.
  4. Enter the name of the book in the Search box and follow the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR/7-Zip for Windows
  • Zipeg/iZip/UnRarX for Mac
  • 7-Zip/PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Rust-Programming-Cookbook. In case there's an update to the code, it will be updated on the existing GitHub repository.

We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Download the color images

Code in Action

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "Mount the downloaded WebStorm-10*.dmg disk image file as another disk in your system."

A block of code is set as follows:

macro_rules! strange_patterns {
(The pattern must match precisely) => { "Text" };
(42) => { "Numeric" };
(;<=,<=;) => { "Alpha" };
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

#[test]
#[should_panic]
fn test_failing_make_fn() {
make_fn!(fail, {assert!(false)});
fail();
}

Any command-line input or output is written as follows:

$ cargo run

Bold: Indicates a new term, an important word, or words that you see on screen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Select System info from the Administration panel."

Warnings or important notes appear like this.
Tips and tricks appear like this.