Rust Essentials: A quick guide to writing fast, safe, and concurrent systems and applications
Book information
Description
Key FeaturesGet started with Rust to build scalable and high performance applicationsEnhance your application development skills using the power of RustDiscover the power of Rust when developing concurrent applications for large and scalable softwareBook Description Rust is the new, open source, fast, and safe systems programming language for the 21st century, developed at Mozilla Research, and with a steadily growing community. It was created to solve the dilemma between high-level, slow code with minimal control over the system, and low-level, fast code with maximum system control. It is no longer necessary to learn C/C++ to develop resource intensive and low-level systems applications. This book will give you a head start to solve systems programming and application tasks with Rust. We start off with an argumentation of Rust's unique place in today's landscape of programming languages. You'll install Rust and learn how to work with its package manager Cargo. The various concepts are introduced step by step: variables, types, functions, and control structures to lay the groundwork. Then we explore more structured data such as strings, arrays, and enums, and you’ll see how pattern matching works. Throughout all this, we stress the unique ways of reasoning that the Rust compiler uses to produce safe code. Next we look at Rust's specific way of error handling, and the overall importance of traits in Rust code. The pillar of memory safety is treated in depth as we explore the various pointer kinds. Next, you’ll see how macros can simplify code generation, and how to compose bigger projects with modules and crates. Finally, you’ll discover how we can write safe concurrent code in Rust and interface with C programs, get a view of the Rust ecosystem, and explore the use of the standard library. What you will learnSet up your Rust environment to achieve the highest productivityBridge the performance gap between safe and unsafe languagesUse pattern matching to create flexible codeApply generics and traits to develop widely applicable codeOrganize your code in modules and cratesBuild macros to extend Rust’s capabilities and reachApply tasks to tackle problems concurrently in a distributed environmentAbout the Author Ivo Balbaert is currently a lecturer in (web) programming and databases at CVO Antwerpen, a community college in Belgium. He received a PhD in applied physics from University of Antwerp in 1986. He worked for 20 years in the software industry as a developer and consultant in several companies and for 10 years as project manager at the University Hospital of Antwerp. From 2000 onward, he switched to partly teaching, developing software, and writing technical books. Table of ContentsSTARTING WITH RUSTUSING VARIABLES AND TYPESUSING FUNCTIONS AND CONTROL STRUCTURESSTRUCTURING DATA AND MATCHING PATTERNSHIGHER-ORDER FUNCTIONS AND ERROR HANDLINGUsing traits and OOP in RustPOINTERS AND MEMORY SAFETYORGANIZING CODE AND MACROSCONCURRENCY AND PARALLELISMPROGRAMMING AT THE BOUNDARIESExploring the standard libraryThe ecosystem of crates Preface......Page 20 What this book covers......Page 21 What you need for this book......Page 23 Who this book is for......Page 24 Conventions......Page 25 Customer support......Page 26 Downloading the example code......Page 27 Errata......Page 28 Piracy......Page 29 Questions......Page 30 Starting with Rust......Page 31 The advantages of Rust......Page 32 The trifecta of Rust - safe, fast, and concurrent......Page 34 Comparison with other languages......Page 36 The stability of Rust and its evolution......Page 37 The success of Rust......Page 39 Where to use Rust......Page 41 Servo......Page 42 Installing Rust......Page 43 rustc--the Rust compiler......Page 45 Our first program......Page 46 Working with Cargo......Page 48 Developer tools......Page 52 Using Sublime Text......Page 53 The Standard Library......Page 55 Summary......Page 56 Using Variables and Types......Page 57 Comments......Page 58 Global constants......Page 59 Printing with string interpolation......Page 61 Values and primitive types......Page 63 Consulting Rust documentation......Page 65 Binding variables to values......Page 66 Mutable and immutable variables......Page 68 Scope of a variable and shadowing......Page 70 Type checking and conversions......Page 71 Aliasing......Page 73 Expressions......Page 74 The stack and the heap......Page 76 Summary......Page 80 Using Functions and Control Structures......Page 81 Branching on a condition......Page 82 Looping......Page 84 Functions......Page 86 Documenting a function......Page 90 Attributes......Page 92 Conditional compilation......Page 93 Testing......Page 94 Testing with cargo......Page 97 The tests module......Page 98 Summary......Page 101 Structuring Data and Matching Patterns......Page 102 Strings......Page 103 Arrays, vectors, and slices......Page 108 Vectors......Page 111 Slices......Page 113 Strings and arrays......Page 114 Tuples......Page 116 Structs......Page 118 Enums......Page 121 Result and Option......Page 122 Getting input from the console......Page 123 Matching patterns......Page 126 Program arguments......Page 132 Summary......Page 134 Higher Order Functions and Error-Handling......Page 135 Higher order functions and closures......Page 136 Iterators......Page 139 Consumers and adapters......Page 141 Generic data structures and functions......Page 144 Error-handling......Page 147 Panics......Page 148 Testing for failure......Page 149 Some more examples of error-handling......Page 151 The try! macro and the ? operator......Page 154 Summary......Page 156 Using Traits and OOP in Rust......Page 157 Associated functions on structs......Page 158 Methods on structs......Page 160 Using a constructor pattern......Page 162 Using a builder pattern......Page 164 Methods on tuples and enums......Page 166 Traits......Page 167 Using trait constraints......Page 170 Static and dynamic dispatch......Page 173 Built-in traits and operator overloading......Page 175 OOP in Rust......Page 177 Inheritance with traits......Page 178 Using the visitor pattern......Page 180 Summary......Page 182 Ensuring Memory Safety and Pointers......Page 183 Pointers and references......Page 184 Stack and heap......Page 185 Lifetimes......Page 186 Copying and moving values - The copy trait......Page 190 Let's summarize......Page 194 Pointers......Page 195 References......Page 197 Match, struct, and ref......Page 200 Ownership and borrowing......Page 202 Ownership......Page 203 Moving a value......Page 204 Borrowing a value......Page 205 Implementing the Drop trait......Page 208 Moving closure......Page 209 Boxes......Page 211 Reference counting......Page 215 Overview of pointers......Page 217 Summary......Page 219 Organizing Code and Macros......Page 220 Modules and crates......Page 221 Building crates......Page 222 Defining a module......Page 224 Visibility of items......Page 225 Importing modules and file hierarchy......Page 228 Importing external crates......Page 231 Exporting a public interface......Page 233 Adding external crates to a project......Page 234 Working with random numbers......Page 236 Macros......Page 238 Why macros?......Page 239 Developing macros......Page 240 Repetition......Page 242 Creating a new function......Page 243 Some other examples......Page 244 Using macros from crates......Page 247 Some other built-in macros......Page 248 Summary......Page 250 Concurrency - Coding for Multicore Execution......Page 251 Concurrency and threads......Page 252 Creating threads......Page 253 Setting the thread's stack size......Page 255 Starting a number of threads......Page 256 Panicking threads......Page 259 Thread safety......Page 260 Shared mutable states......Page 261 The Sync trait......Page 264 Communication through channels......Page 265 Sending and receiving data......Page 266 Making a channel......Page 268 Sending struct values over a channel......Page 269 Sending references over a channel......Page 270 Synchronous and asynchronous......Page 272 Summary......Page 274 Programming at the Boundaries......Page 275 When is code unsafe......Page 276 Using std::mem......Page 278 Raw pointers......Page 279 Interfacing with C......Page 281 Using a C library......Page 283 Inlining assembly code......Page 285 Calling Rust from other languages......Page 287 Summary......Page 288 Exploring the Standard Library......Page 289 Exploring std and the prelude module......Page 290 Collections - using hashmaps and hashsets......Page 291 Working with files......Page 294 Paths......Page 295 Reading a file......Page 297 Error-handling with try!......Page 299 Buffered reading......Page 300 Writing a file......Page 302 Error-handling with try!......Page 304 Filesystem operations......Page 305 Using Rust without the Standard Library......Page 306 Summary......Page 307 The Ecosystem of Crates......Page 308 The ecosystem of crates......Page 309 Working with dates and times......Page 310 File formats and databases......Page 312 Web development......Page 315 Graphics and games......Page 318 OS and embedded system development......Page 320 Other resources for learning Rust......Page 321 Summary......Page 322
Similar books
Julia 1.0 Programming Complete Reference Guide
2019 · PDF
Learn Red - Fundamentals of Red: Get Up and Running with the Red Language for Full-Stack Development
2018 · EPUB
Julia 1.0 Programming: Dynamic and high-performance programming to build fast scientific applications
2018 · PDF
Programming Crystal: Create High-Performance, Safe, Concurrent Apps
2019 · PDF
Programming Crystal Create High-Performance, Safe, Concurrent Apps
2019 · PDF
Julia 1.0 Programming Dynamic and High-Performance Programming to Build Fast Scientific Applications
2018 · EPUB
Rust Essentials: A quick guide to writing fast, safe, and concurrent systems and applications
2017 · EPUB
Rust Essentials: A quick guide to writing fast, safe, and concurrent systems and applications
2017 · PDF