Book Image

Rust Cookbook

By : Vigneshwer Dhinakaran
Book Image

Rust Cookbook

By: Vigneshwer Dhinakaran

Overview of this book

<p>If you are building concurrent applications, server-side programs, or high-performance applications, you will benefit from this language. This book comes with a lot of application-specific recipes to kick-start your development of real-world high-performance applications with the Rust programming language and integrating Rust units into your existing applications. In this book, you will find some 80 practical recipes written in Rust that will allow you to use the code samples right away in your existing applications. These recipes have been tested with stable rust compiler versions of 1.14.0 and above.</p> <p>This book will help you understand the core concepts of the Rust language, enabling you to develop efficient and high-performance applications by incorporating features such as zero cost abstraction and better memory management.</p> <p>We’ll delve into advanced-level concepts such as error handling, macros, crates, and parallelism in Rust. Toward the end of the book, you will learn how to create HTTP servers and web services, building a strong foundational knowledge in server-side programming and enabling you to deliver solutions to build high-performance and safer production-level web applications and services using Rust.</p>
Table of Contents (19 chapters)
Title
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Creating a file hierarchy


This recipe discusses how to create a file structure for complex and bigger code bases so that it would be easier for the developer to manage application feature development. We will learn about the rules enforced by the Rust compiler to create a file hierarchy successfully so that the developer can utilize and get the same flexibility while using modules' units.

Getting ready

We will require the Rust compiler and any text editor to code. Also, create a file named sample_module.rs in the project workspace.

How to do it...

  1. Create a file named sample_split.rs and a folder named sample_module in the project workspace:
      touch sample_split.rs && mkdir sample_module
  1. Create the mod.rs, nested_mod.rs, and sample_private.rs files inside the sample_module folder:
      cd sample_module && touch mod.rs nested_mod.rs
      sample_private.rs

We should get a folder structure, as shown in the following screenshot:

  1. Write the code header with the details of the code...