Mastering Rust

Discover the powerful, hidden features of Rust you need to build robust, concurrent, and fast applications

Mastering Rust

This ebook is included in a Mapt subscription
Vesa Kaihlavirta

Discover the powerful, hidden features of Rust you need to build robust, concurrent, and fast applications
$0.00
$20.00
$49.99
$29.99p/m after trial
RRP $39.99
RRP $49.99
Subscription
eBook
Print + eBook
Start 30 Day Trial
Subscribe and access every Packt eBook & Video.
 
  • 4,000+ eBooks & Videos
  • 40+ New titles a month
  • 1 Free eBook/Video to keep every month
Start Free Trial
 
Preview in Mapt

Book Details

ISBN 139781785885303
Paperback354 pages

Book Description

If concurrent programs are giving you sleepless nights, Rust is your go-to language. Being one of the first ever comprehensive books on Rust, it is filled with real-world examples and explanations, showing you how you can build scalable and reliable programs for your organization.

We’ll teach you intermediate to advanced level concepts that make Rust a great language. Improving performance, using generics, building macros, and working with threads are just some of the topics we’ll cover. We’ll talk about the official toolsets and ways to discover more. The book contains a mix of theory interspersed with hands-on tasks, so you acquire the skills as well as the knowledge. Since programming cannot be learned by just reading, we provide exercises (and solutions) to hammer the concepts in.

After reading this book, you will be able to implement Rust for your enterprise project, deploy the software, and will know the best practices of coding in Rust.

Table of Contents

Chapter 1: Getting Your Feet Wet
What is Rust and why should you care?
Installing Rust compiler and Cargo
A tour of the language and trying it out
Struct methods
Summary
Chapter 2: Using Cargo to Build Your First Program
Cargo and crates
Founding a project - cargo init
Dependencies, building, and running
Running tests - cargo test
Cargo.toml - project metadata
Editor integrations
Final exercise - starting our project
Summary
Chapter 3: Unit Testing and Benchmarking
Motivation and high-level view
Founding a city-builder game
Summary
Chapter 4: Types
String types
Arrays and slices
Generic types
Traits and implementations
Constants and statics
Summary
Chapter 5: Error Handling
Option and Result
Unwrapping
Mapping of the Option/Result values
Early returns and the try! macro
Panicking
Custom errors and the Error trait
Exercise
Summary
Chapter 6: Memory, Lifetimes, and Borrowing
LLVM
Function variables and the stack
The heap
Memory safety
Ownership
Lifetimes
The Drop trait
Collector types
Inspecting memory usage with std::mem
Final exercises
Summary
Chapter 7: Concurrency
Problems with concurrency
Closures
Threads
Sharing the Copy types
Channels
Locks and mutexes
Atomic Rc
The final exercise
Summary
Chapter 8: Macros
Introduction to metaprogramming
Dissecting println!
Debugging macros
Macro keywords
Repeating constructs
Example - an HTTP tester
Exercises
Summary
Chapter 9: Compiler Plugins
Basics of compiler plugins
Code generation as a workaround
Aster
Linter plugins
Macros 1.1 - custom derives
Exercises
Summary
Chapter 10: Unsafety and Interfacing with Other Languages
Unsafety
Calling C code from Rust
Connecting external libraries to Rust code
Creating Ruby extensions with Ruru
JavaScript/Node.js and Neon
Exercises
Summary
Chapter 11: Parsing and Serialization
Parsing fundamentals
Other parser libraries
Exercises
Summary
Chapter 12: Web Programming
Introduction to Rust and web programming
Hyper as a client
Hyper as a server
Rocket
Other web frameworks
Exercises
Summary
Chapter 13: Data Storage
SQLite
PostgreSQL
Connection pooling with r2d2
Diesel
Summary
Chapter 14: Debugging
Introduction to debugging
Exercises
Summary
Chapter 15: Solutions and Final Words
Chapter 1 - Getting Your Feet Wet
Chapter 2 - Using Cargo to Build Your First Program
Chapter 3 - Unit Testing and Benchmarking
Chapter 4 - Types
Chapter 5 - Error Handling
Chapter 6 - Memory, Lifetimes, and Borrowing
Chapter 7 - Concurrency
Chapter 8 - Macros
Chapter 9 - Compiler Plugins
Chapter 10 - Unsafety and Interfacing with Other Languages
Chapter 11 - Parsing and Serialization
Chapter 12 - Web Programming
Chapter 13 - Data Storage
Chapter 14 - Debugging

What You Will Learn

  • Implement unit testing patterns with the standard Rust tools
  • Get to know the different philosophies of error handling and how to use them wisely
  • Appreciate Rust's ability to solve memory allocation problems safely without garbage collection
  • Get to know how concurrency works in Rust and use concurrency primitives such as threads and message passing
  • Use syntax extensions and write your own
  • Create a Web application with Rocket
  • Use Diesel to build safe database abstractions

Authors

Table of Contents

Chapter 1: Getting Your Feet Wet
What is Rust and why should you care?
Installing Rust compiler and Cargo
A tour of the language and trying it out
Struct methods
Summary
Chapter 2: Using Cargo to Build Your First Program
Cargo and crates
Founding a project - cargo init
Dependencies, building, and running
Running tests - cargo test
Cargo.toml - project metadata
Editor integrations
Final exercise - starting our project
Summary
Chapter 3: Unit Testing and Benchmarking
Motivation and high-level view
Founding a city-builder game
Summary
Chapter 4: Types
String types
Arrays and slices
Generic types
Traits and implementations
Constants and statics
Summary
Chapter 5: Error Handling
Option and Result
Unwrapping
Mapping of the Option/Result values
Early returns and the try! macro
Panicking
Custom errors and the Error trait
Exercise
Summary
Chapter 6: Memory, Lifetimes, and Borrowing
LLVM
Function variables and the stack
The heap
Memory safety
Ownership
Lifetimes
The Drop trait
Collector types
Inspecting memory usage with std::mem
Final exercises
Summary
Chapter 7: Concurrency
Problems with concurrency
Closures
Threads
Sharing the Copy types
Channels
Locks and mutexes
Atomic Rc
The final exercise
Summary
Chapter 8: Macros
Introduction to metaprogramming
Dissecting println!
Debugging macros
Macro keywords
Repeating constructs
Example - an HTTP tester
Exercises
Summary
Chapter 9: Compiler Plugins
Basics of compiler plugins
Code generation as a workaround
Aster
Linter plugins
Macros 1.1 - custom derives
Exercises
Summary
Chapter 10: Unsafety and Interfacing with Other Languages
Unsafety
Calling C code from Rust
Connecting external libraries to Rust code
Creating Ruby extensions with Ruru
JavaScript/Node.js and Neon
Exercises
Summary
Chapter 11: Parsing and Serialization
Parsing fundamentals
Other parser libraries
Exercises
Summary
Chapter 12: Web Programming
Introduction to Rust and web programming
Hyper as a client
Hyper as a server
Rocket
Other web frameworks
Exercises
Summary
Chapter 13: Data Storage
SQLite
PostgreSQL
Connection pooling with r2d2
Diesel
Summary
Chapter 14: Debugging
Introduction to debugging
Exercises
Summary
Chapter 15: Solutions and Final Words
Chapter 1 - Getting Your Feet Wet
Chapter 2 - Using Cargo to Build Your First Program
Chapter 3 - Unit Testing and Benchmarking
Chapter 4 - Types
Chapter 5 - Error Handling
Chapter 6 - Memory, Lifetimes, and Borrowing
Chapter 7 - Concurrency
Chapter 8 - Macros
Chapter 9 - Compiler Plugins
Chapter 10 - Unsafety and Interfacing with Other Languages
Chapter 11 - Parsing and Serialization
Chapter 12 - Web Programming
Chapter 13 - Data Storage
Chapter 14 - Debugging

Book Details

ISBN 139781785885303
Paperback354 pages
Read More

Read More Reviews