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 new project using Cargo


Cargo is a unique offering from Rust and is very new in the sphere of system programming. It is also one of the selling points of Rust, as it enables developers to package, ship, and test their Rust application.

We will cover a lot of functionalities of Cargo in this chapter.

Getting ready

We require the Rust compiler, Cargo, and any text editor for coding.

How to do it...

  1. Open the Terminal.
  2. Go to the directory where you want to create the project:
      cd project_location
  1. Enter the following command to create a new Rust project:
      cargo new project_name --bin

Create a project named hello_world, as shown in the following example:

      cargo new hello_world --bin

You should get the following output:

  1. You should have a new folder created with the name of the project.

First, get into the project and examine it:

      cd hello_world
      tree .

You should get the following output:

This is the whole structure of the newly created project.

  1. Print the content of the Cargo...