Rust Cookbook
Book information
Description
75-80 recipes for learning Rust programming About This Book Learn to build high-performance Rust units and integrate them into your existing application Work through recipes on performance, robustness, security, memory management, and scalability Work through recipes to build foreign function interface with C, JS, and Python Who This Book Is For If you want to write Rust programs, then this book is for you. This book is for those who have a basic knowledge of Rust or any programming language. If you are a C/C developer who is migrating to Rust for various reasons, this book is ideal for you. What You Will Learn Understand system programming language problems and see how Rust provides unique solutions Get to know the core concepts of Rust to develop fast and safe applications Explore the possibility of integrating Rust units into existing applications to make them more efficient Achieve better parallelism, security, and performance Explore ways to package your Rust application and ship it for deployment in a production environment Discover how to build web applications and services using Rust to provide high-performance to the end user In Detail 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. 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. 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. Style and approach This book helps you learn the core concepts of Rust faster by taking a recipe-based approach, where you can try out different code snippets to understand a concept. Cover -- Copyright -- Credits -- About the Author -- Acknowledgments -- About the Reviewer -- www.PacktPub.com -- Customer Feedback -- Table of Contents -- Preface -- Chapter 1: Let us Make System Programming Great Again -- Introduction -- Setting up Rust in Linux and macOS -- Getting ready -- How to do it ... -- Uninstalling Rust -- Rust's compiler version -- Advanced installation options -- Troubleshooting -- How it works ... -- Setting up Rust in Windows -- Getting ready -- How to do it ... -- How it works ... -- Creating your first Rust program -- Getting ready -- How to do it ... -- How it works ... -- Defining a variable assignment -- Getting ready -- How to do it ... -- How it works ... -- Setting up Boolean and the character types -- Getting ready -- How to do it ... -- How it works ... -- Controlling decimal points, number formats, and named arguments -- Getting ready -- How to do it ... -- How it works ... -- Performing arithmetic operations -- Getting ready -- How to do it ... -- How it works ... -- Defining mutable variables -- Getting ready -- How to do it ... -- How it works ... -- Declaring and performing string operations -- Getting ready -- How to do it ... -- How it works ... -- Declaring arrays and using slices in Rust -- Getting ready -- How to do it ... -- How it works ... -- Declaring vectors in Rust -- Getting ready -- How to do it ... -- How it works ... -- Declaring tuples in Rust -- Getting ready -- How to do it ... -- How it works ... -- Performing calculations on two numbers -- Getting ready -- How to do it ... -- How it works ... -- Chapter 2: Advanced Programming with Rust -- Introduction -- Defining an expression -- Getting ready -- How to do it ... -- How it works ... -- Defining constants -- Getting ready -- How to do it ... -- How it works ... -- Performing variable bindings -- Getting ready -- How to do it ... -- How it works Performing type casting in Rust -- Getting ready -- How to do it ... -- How it works ... -- Decision-making with Rust -- Getting ready -- How to do it ... -- How it works ... -- Looping operations in Rust -- Getting ready -- How to do it ... -- How it works ... -- Defining the enum type -- Getting ready -- How to do it ... -- How it works ... -- Defining closures -- Getting ready -- How to do it ... -- How it works ... -- Performing pointer operations in Rust -- Getting ready -- How to do it ... -- How it works ... -- Defining your first user-defined data type -- Getting ready -- How to do it ... -- How it works ... -- Adding functionality to the user-defined data type -- Getting ready -- How to do it ... -- How it works ... -- Similar functionality for different data type -- Getting ready -- How to do it ... -- How it works ... -- Chapter 3: Deep Diving into Cargo -- Introduction -- Creating a new project using Cargo -- Getting ready -- How to do it ... -- How it works ... -- Downloading an external crate from crates.io -- Getting ready -- How to do it ... -- How it works ... -- Working on existing Cargo projects -- Getting ready -- How to do it ... -- How it works ... -- Running tests with Cargo -- Getting ready -- How to do it ... -- How it works ... -- Configuration management of the project -- Getting ready -- How to do it ... -- How it works ... -- Building the project on the Travis CI -- Getting ready -- How to do it ... -- How it works ... -- Uploading to crates.io -- Getting ready -- How to do it ... -- How it works ... -- Chapter 4: Creating Crates and Modules -- Introduction -- Defining a module in Rust -- Getting ready -- How to do it ... -- How it works ... -- Building a nested module -- Getting ready -- How to do it ... -- How it works ... -- Creating a module with struct -- Getting ready -- How to do it ... -- How it works ... -- Controlling modules -- Getting ready How to do it ... -- How it works ... -- Accessing modules -- Getting ready -- How to do it ... -- How it works ... -- Creating a file hierarchy -- Getting ready -- How to do it ... -- How it works ... -- Building libraries in Rust -- Getting ready -- How to do it ... -- How it works ... -- Calling external crates -- Getting ready -- How to do it ... -- How it works ... -- Chapter 5: Deep Dive into Parallelism -- Introduction -- Creating a thread in Rust -- Getting ready -- How to do it ... -- How it works ... -- Spawning multiple threads -- Getting ready -- How to do it ... -- How it works ... -- Holding threads in a vector -- Getting ready -- How to do it ... -- How it works ... -- Sharing data between threads using channels -- Getting ready -- How to do it ... -- How it works ... -- Implementing safe mutable access -- Getting ready -- How to do it ... -- How it works ... -- Creating child processes -- Getting ready -- How to do it ... -- How it works ... -- Waiting for a child process -- Getting ready -- How to do it ... -- How it works ... -- Making sequential code parallel -- Getting ready -- How to do it ... -- How it works ... -- Chapter 6: Efficient Error Handling -- Introduction -- Implementing panic -- Getting ready -- How to do it ... -- How it works ... -- Implementing Option -- Getting ready -- How to do it ... -- How it works ... -- Creating map combinator -- Getting ready -- How to do it ... -- How it works ... -- Creating and_then combinator -- Getting ready -- How to do it ... -- How it works ... -- Creating map for the Result type -- Getting ready -- How to do it ... -- How it works ... -- Implementing aliases -- Getting ready -- How to do it ... -- How it works ... -- Handling multiple errors -- Getting ready -- How to do it ... -- How it works ... -- Implementing early returns -- Getting ready -- How to do it ... -- How it works ... -- Implementing the try! macro Getting ready -- How to do it ... -- How it works ... -- Defining your own error types -- Getting ready -- How to do it ... -- How it works ... -- Implementing the boxing of errors -- Getting ready -- How to do it ... -- How it works ... -- Chapter 7: Hacking Macros -- Introduction -- Building macros in Rust -- Getting ready -- How to do it ... -- How it works ... -- Implementing matching in macros -- Getting ready -- How to do it ... -- How it works ... -- Playing with common Rust macros -- Getting ready -- How to do it ... -- How it works ... -- Implementing designators -- Getting ready -- How to do it ... -- How it works ... -- Overloading macros -- Getting ready -- How to do it ... -- How it works ... -- Implementing repeat -- Getting ready -- How to do it ... -- How it works ... -- Implementing DRY -- Getting ready -- How to do it ... -- How it works ... -- Chapter 8: Integrating Rust with Other Languages -- Introduction -- Calling C operations from Rust -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust commands from C -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust operations from Node.js apps -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust operations from Python -- Getting ready -- How to do it ... -- How it works ... -- Writing a Python module in Rust -- Getting ready -- How to do it ... -- How it works ... -- Chapter 9: Web Development with Rust -- Introduction -- Setting up a web server -- Getting ready -- How to do it ... -- How it works ... -- Creating endpoints -- Getting ready -- How to do it ... -- How it works ... -- Handling JSONRequests -- Getting ready -- How to do it ... -- How it works ... -- Building custom error handlers -- Getting ready -- How to do it ... -- How it works ... -- Hosting templates -- Getting ready -- How to do it ... -- How it works Chapter 10: Advanced Web Development in Rust -- Introduction -- Setting up the API -- Getting ready -- How to do it ... -- How it works ... -- Saving user data in MongoDB -- Getting ready -- How to do it ... -- Fetching user data -- Getting ready -- How to do it ... -- How it works ... -- Deleting user data -- Getting ready -- How to do it ... -- How it works ... -- Chapter 11: Advanced Rust Tools and Libraries -- Introduction -- Setting up rustup -- Getting ready -- How to do it ... -- How it works ... -- Setting up rustfmt -- Getting ready -- How to do it ... -- How it works ... -- Setting up rust-clippy -- Getting ready -- How to do it ... -- How it works ... -- Setting up and testing with Servo -- Getting ready -- How to do it ... -- How it works ... -- Generating random numbers -- Getting ready -- How to do it ... -- How it works ... -- Writing lines to a file -- Getting ready -- How to do it ... -- How it works ... -- Parsing unstructured JSON -- Getting ready -- How to do it ... -- How it works ... -- Parsing URL from a string -- Getting ready -- How to do it ... -- How it works ... -- Decompressing a tarball -- Getting ready -- How to do it ... -- How it works ... -- Compressing a directory to a tarball -- Getting ready -- How to do it ... -- How it works ... -- Finding file extensions recursively -- Getting ready -- How to do it ... -- How it works ... -- Index Read more... Abstract: Cover -- Copyright -- Credits -- About the Author -- Acknowledgments -- About the Reviewer -- www.PacktPub.com -- Customer Feedback -- Table of Contents -- Preface -- Chapter 1: Let us Make System Programming Great Again -- Introduction -- Setting up Rust in Linux and macOS -- Getting ready -- How to do it ... -- Uninstalling Rust -- Rust's compiler version -- Advanced installation options -- Troubleshooting -- How it works ... -- Setting up Rust in Windows -- Getting ready -- How to do it ... -- How it works ... -- Creating your first Rust program -- Getting ready -- How to do it ... -- How it works ... -- Defining a variable assignment -- Getting ready -- How to do it ... -- How it works ... -- Setting up Boolean and the character types -- Getting ready -- How to do it ... -- How it works ... -- Controlling decimal points, number formats, and named arguments -- Getting ready -- How to do it ... -- How it works ... -- Performing arithmetic operations -- Getting ready -- How to do it ... -- How it works ... -- Defining mutable variables -- Getting ready -- How to do it ... -- How it works ... -- Declaring and performing string operations -- Getting ready -- How to do it ... -- How it works ... -- Declaring arrays and using slices in Rust -- Getting ready -- How to do it ... -- How it works ... -- Declaring vectors in Rust -- Getting ready -- How to do it ... -- How it works ... -- Declaring tuples in Rust -- Getting ready -- How to do it ... -- How it works ... -- Performing calculations on two numbers -- Getting ready -- How to do it ... -- How it works ... -- Chapter 2: Advanced Programming with Rust -- Introduction -- Defining an expression -- Getting ready -- How to do it ... -- How it works ... -- Defining constants -- Getting ready -- How to do it ... -- How it works ... -- Performing variable bindings -- Getting ready -- How to do it ... -- How it works Performing type casting in Rust -- Getting ready -- How to do it ... -- How it works ... -- Decision-making with Rust -- Getting ready -- How to do it ... -- How it works ... -- Looping operations in Rust -- Getting ready -- How to do it ... -- How it works ... -- Defining the enum type -- Getting ready -- How to do it ... -- How it works ... -- Defining closures -- Getting ready -- How to do it ... -- How it works ... -- Performing pointer operations in Rust -- Getting ready -- How to do it ... -- How it works ... -- Defining your first user-defined data type -- Getting ready -- How to do it ... -- How it works ... -- Adding functionality to the user-defined data type -- Getting ready -- How to do it ... -- How it works ... -- Similar functionality for different data type -- Getting ready -- How to do it ... -- How it works ... -- Chapter 3: Deep Diving into Cargo -- Introduction -- Creating a new project using Cargo -- Getting ready -- How to do it ... -- How it works ... -- Downloading an external crate from crates.io -- Getting ready -- How to do it ... -- How it works ... -- Working on existing Cargo projects -- Getting ready -- How to do it ... -- How it works ... -- Running tests with Cargo -- Getting ready -- How to do it ... -- How it works ... -- Configuration management of the project -- Getting ready -- How to do it ... -- How it works ... -- Building the project on the Travis CI -- Getting ready -- How to do it ... -- How it works ... -- Uploading to crates.io -- Getting ready -- How to do it ... -- How it works ... -- Chapter 4: Creating Crates and Modules -- Introduction -- Defining a module in Rust -- Getting ready -- How to do it ... -- How it works ... -- Building a nested module -- Getting ready -- How to do it ... -- How it works ... -- Creating a module with struct -- Getting ready -- How to do it ... -- How it works ... -- Controlling modules -- Getting ready How to do it ... -- How it works ... -- Accessing modules -- Getting ready -- How to do it ... -- How it works ... -- Creating a file hierarchy -- Getting ready -- How to do it ... -- How it works ... -- Building libraries in Rust -- Getting ready -- How to do it ... -- How it works ... -- Calling external crates -- Getting ready -- How to do it ... -- How it works ... -- Chapter 5: Deep Dive into Parallelism -- Introduction -- Creating a thread in Rust -- Getting ready -- How to do it ... -- How it works ... -- Spawning multiple threads -- Getting ready -- How to do it ... -- How it works ... -- Holding threads in a vector -- Getting ready -- How to do it ... -- How it works ... -- Sharing data between threads using channels -- Getting ready -- How to do it ... -- How it works ... -- Implementing safe mutable access -- Getting ready -- How to do it ... -- How it works ... -- Creating child processes -- Getting ready -- How to do it ... -- How it works ... -- Waiting for a child process -- Getting ready -- How to do it ... -- How it works ... -- Making sequential code parallel -- Getting ready -- How to do it ... -- How it works ... -- Chapter 6: Efficient Error Handling -- Introduction -- Implementing panic -- Getting ready -- How to do it ... -- How it works ... -- Implementing Option -- Getting ready -- How to do it ... -- How it works ... -- Creating map combinator -- Getting ready -- How to do it ... -- How it works ... -- Creating and_then combinator -- Getting ready -- How to do it ... -- How it works ... -- Creating map for the Result type -- Getting ready -- How to do it ... -- How it works ... -- Implementing aliases -- Getting ready -- How to do it ... -- How it works ... -- Handling multiple errors -- Getting ready -- How to do it ... -- How it works ... -- Implementing early returns -- Getting ready -- How to do it ... -- How it works ... -- Implementing the try! macro Getting ready -- How to do it ... -- How it works ... -- Defining your own error types -- Getting ready -- How to do it ... -- How it works ... -- Implementing the boxing of errors -- Getting ready -- How to do it ... -- How it works ... -- Chapter 7: Hacking Macros -- Introduction -- Building macros in Rust -- Getting ready -- How to do it ... -- How it works ... -- Implementing matching in macros -- Getting ready -- How to do it ... -- How it works ... -- Playing with common Rust macros -- Getting ready -- How to do it ... -- How it works ... -- Implementing designators -- Getting ready -- How to do it ... -- How it works ... -- Overloading macros -- Getting ready -- How to do it ... -- How it works ... -- Implementing repeat -- Getting ready -- How to do it ... -- How it works ... -- Implementing DRY -- Getting ready -- How to do it ... -- How it works ... -- Chapter 8: Integrating Rust with Other Languages -- Introduction -- Calling C operations from Rust -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust commands from C -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust operations from Node.js apps -- Getting ready -- How to do it ... -- How it works ... -- Calling Rust operations from Python -- Getting ready -- How to do it ... -- How it works ... -- Writing a Python module in Rust -- Getting ready -- How to do it ... -- How it works ... -- Chapter 9: Web Development with Rust -- Introduction -- Setting up a web server -- Getting ready -- How to do it ... -- How it works ... -- Creating endpoints -- Getting ready -- How to do it ... -- How it works ... -- Handling JSONRequests -- Getting ready -- How to do it ... -- How it works ... -- Building custom error handlers -- Getting ready -- How to do it ... -- How it works ... -- Hosting templates -- Getting ready -- How to do it ... -- How it works Chapter 10: Advanced Web Development in Rust -- Introduction -- Setting up the API -- Getting ready -- How to do it ... -- How it works ... -- Saving user data in MongoDB -- Getting ready -- How to do it ... -- Fetching user data -- Getting ready -- How to do it ... -- How it works ... -- Deleting user data -- Getting ready -- How to do it ... -- How it works ... -- Chapter 11: Advanced Rust Tools and Libraries -- Introduction -- Setting up rustup -- Getting ready -- How to do it ... -- How it works ... -- Setting up rustfmt -- Getting ready -- How to do it ... -- How it works ... -- Setting up rust-clippy -- Getting ready -- How to do it ... -- How it works ... -- Setting up and testing with Servo -- Getting ready -- How to do it ... -- How it works ... -- Generating random numbers -- Getting ready -- How to do it ... -- How it works ... -- Writing lines to a file -- Getting ready -- How to do it ... -- How it works ... -- Parsing unstructured JSON -- Getting ready -- How to do it ... -- How it works ... -- Parsing URL from a string -- Getting ready -- How to do it ... -- How it works ... -- Decompressing a tarball -- Getting ready -- How to do it ... -- How it works ... -- Compressing a directory to a tarball -- Getting ready -- How to do it ... -- How it works ... -- Finding file extensions recursively -- Getting ready -- How to do it ... -- How it works ... -- Index
Similar books
Rust Cookbook
2017 · PDF
Rust Cookbook
2017 · AZW3
EXCEL 2023 CRASH COURSE: Master Excel 2023 With This Complete Crash Course In 7 Days
2022 · EPUB
The arraignment and tryall with a declaration of the Ranters also, several sentences proceedings at the sessions in the Old-Baily, and Councel of War: their protestations and the hanging of one up by the thumbs; with divers penalties to be inflicted upon others. The dancing and revelling of Dr. Buckeridge and his wife, and other gent. dancing all in white, in Berkshire, and their Christmas carol. A dispute between a Ranter in Bridewel, and one that came to see him; with his creed and pater noster: and the names of the false gods they worship. As also, a list of many of the Ranters, from whence they are derived: and of many hundreds of them in England
2019 · EPUB
The discoverer; vvherein is set forth (to undeceive the nation) the reall plots and stratagems of Lievt. Col. John Lilburn, Mr. William Walwyn, Mr. Thomas Prince, Mr. Richard Overton, and that partie ... Namely, under the pretence and colour of libertie ... a most dangerous and destructive designe is carried on to deprive the nation of their religion, rights, liberties, proprieties, lawes, government, &c. and to bring a totall and universall ruine upon the land. And so much is here clearely proved. The first part
2019 · EPUB
An act to impower Sir John Molesworth: Baronet, and Joseph Moyle, Esquire, Two of the surviving Trustees, in an Indenture, dated the Twenty-Fifth Day of December One thousand Seven hundred and Forty-Three, to raise the several Sums in the said Indenture mentioned, or such of them as are still unsatisfied, and pay the same, as well as the rest of the personal Estate of Hugh Gregor, deceased, to such Person as Jane Gregor, an Infant, shall marry during her Infancy, with the Consent of the surviving Trustees, and of her Guardians
EPUB
Case Histories
2008 · EPUB
Pandora's Seed: The Unforeseen Cost of Civilization
2010 · EPUB