Rust Programming Cookbook: Explore the latest features of Rust 2018 for building fast and secure apps

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Practical solutions to overcome challenges in creating console and web applications and working with systems-level and embedded code, network programming, deep neural networks, and much more.

Key Features

  • Work through recipes featuring advanced concepts such as concurrency, unsafe code, and macros to migrate your codebase to the Rust programming language
  • Learn how to run machine learning models with Rust
  • Explore error handling, macros, and modularization to write maintainable code

Book Description

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.

What you will learn

  • Understand how Rust provides unique solutions to solve system programming language problems
  • Grasp the core concepts of Rust to develop fast and safe applications
  • Explore the possibility of integrating Rust units into existing applications for improved efficiency
  • Discover how to achieve better parallelism and security with Rust
  • Write Python extensions in Rust
  • Compile external assembly files and use the Foreign Function Interface (FFI)
  • Build web applications and services using Rust for high performance

Who this book is for

The Rust cookbook is for software developers looking to enhance their knowledge of Rust and leverage its features using modern programming practices. Familiarity with Rust language is expected to get the most out of this book.

Table of Contents

  1. Starting off with Rust
  2. Going further with advanced programming
  3. Managing projects with cargo
  4. Fearless Concurrency
  5. Handling errors and other results
  6. Express yourself with macros
  7. Integrating Rust with Other Languages
  8. Safe programming for the web
  9. Systems programming made easy.
  10. Getting practical with Rust

Author(s): Claus Matzinger
Publisher: Packt Publishing
Year: 2019

Language: English
Commentary: True PDF
Pages: 444

Cover
Title Page
Copyright and Credits
Dedication
About Packt
Foreword
Contributors
Table of Contents
Preface
Chapter 1: Starting Off with Rust
Setting up your environment
Getting ready
How to do it...
Managing the Rust installation with rustup.rs
Installing Visual Studio Code and extensions
Troubleshooting
How it works...
Working with the command line I/O
How to do it...
How it works...
Creating and using data types
How to do it...
How it works...
Controlling execution flow
How to do it...
How it works...
Splitting your code with crates and modules
Getting ready
How to do it...
How it works...
Writing tests and benchmarks
Getting ready
How to do it...
How it works...
Documenting your code
Getting ready
How to do it...
How it works...
Testing your documentation
Getting ready
How to do it...
How it works...
Sharing code among types
How to do it...
How it works...
Sequence types in Rust
How to do it...
How it works...
Debugging Rust
Getting ready
How to do it...
How it works...
Chapter 2: Going Further with Advanced Rust
Creating meaningful numbers with enums
How to do it...
How it works...
There is no null
How to do it...
How it works...
Complex conditions with pattern matching
How to do it...
How it works...
Implementing custom iterators
Getting ready
How to do it...
How it works...
Filtering and transforming sequences efficiently
Getting ready
How to do it...
How it works...
Reading memory the unsafe way
How to do it...
How it works...
Shared ownership
Getting ready
How to do it...
How it works...
Shared mutable ownership
Getting ready
How to do it...
How it works...
Referencing with explicit lifetimes
How to do it...
How it works...
Enforcing behavior with trait bounds
How to do it...
How it works...
Working with generic data types
How to do it...
How it works...
Chapter 3: Managing Projects with Cargo
Organizing large projects with workspaces
How to do it...
How it works...
Uploading to crates.io
Getting ready
How to do it...
How it works...
Using dependencies and external crates
How to do it...
How it works...
See also...
Extending cargo with sub-commands
Getting ready
How to do it...
How it works...
Testing your project with cargo
How to do it...
How it works...
Continuous integration with cargo
Getting ready
How to do it...
How it works...
Customizing the build
How to do it...
How it works...
Chapter 4: Fearless Concurrency
Moving data into new threads
How to do it...
How it works...
Managing multiple threads
How to do it...
How it works...
Using channels to communicate between threads
How to do it...
How it works...
Sharing mutable states
How to do it...
How it works...
Multiprocessing in Rust
How to do it...
How it works...
Making sequential code parallel
How to do it...
How it works...
Concurrent data processing in vectors
How to do it...
How it works...
Shared immutable states
How to do it...
How it works...
Handling asynchronous messages with actors
How to do it...
How it works...
Asynchronous programming with futures
How to do it...
How it works...
Chapter 5: Handling Errors and Other Results
Panicking responsibly
How to do it...
How it works...
Handling multiple errors
How to do it...
How it works...
Working with exceptional results
How to do it...
How it works...
Seamless error handling
How to do it...
How it works...
Customizing errors
How to do it...
How it works...
Resilient programming
How to do it...
How it works...
Working with external crates for error handling
How to do it...
How it works...
Moving between Option and Result
How to do it...
How it works...
Chapter 6: Expressing Yourself with Macros
Building custom macros in Rust
How to do it...
How it works...
Implementing matching with macros
How to do it...
How it works...
Using predefined macros
How to do it...
How it works...
Code generation using macros
How to do it...
How it works...
Macro overloading
How to do it...
How it works...
Using repeat for parameter ranges
How to do it...
How it works...
Don't Repeat Yourself 
How to do it...
How it works...
Chapter 7: Integrating Rust with Other Languages
Including legacy C code
Getting ready
How to do it...
How it works...
Calling into Rust from Node.js using FFI
Getting ready
How to do it ...
How it works...
Running Rust in the browser
Getting ready
How to do it...
How it works...
Using Rust and Python 
Getting ready
How to do it...
How it works...
Generating bindings for legacy applications
Getting ready
How to do it...
How it works...
Chapter 8: Safe Programming for the Web
Setting up a web server
Getting ready
How to do it...
How it works...
Designing a RESTful API
Getting ready
How to do it...
How it works...
Handling JSON payloads
Getting ready
How to do it...
How it works...
Web error handling
Getting ready
How to do it...
How it works...
Rendering HTML templates
Getting ready
How to do it...
How it works...
Using an ORM to save data to a database
Getting ready
How to do it...
How it works...
Running advanced queries using an ORM
Getting ready
How to do it...
How it works...
Authentication on the web
Getting ready
How to do it...
How it works...
Chapter 9: Systems Programming Made Easy
Cross-compiling Rust
Getting ready
How to do it...
How it works...
There's more...
Creating I2C device drivers
How to do it...
How it works...
Efficiently reading hardware sensors
How to do it...
How it works...
Chapter 10: Getting Practical with Rust
Generating random numbers
How to do it...
How it works...
Writing to and reading from files
Getting ready
How to do it...
How it works...
Parsing unstructured formats like JSON
Getting ready
How to do it...
How it works...
Extract text using regular expressions
How to do it... 
How it works...
Recursively searching the filesystem
How to do it...
How it works...
Custom command-line arguments
How to do it...
How it works...
Working with piped input data
Getting ready
How to do it...
How it works...
Sending web requests
How to do it...
How it works...
Running machine learning models
Getting ready
How to do it...
How it works...
Configuring and using logging
How to do it...
How it works...
Starting subprocesses
How to do it...
How it works...
Other Books You May Enjoy
Index