Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Title Page
Copyright
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Getting Your Feet Wet
What is Rust and why should you care?
Installing Rust compiler and Cargo
Using rustup.rs
A tour of the language and trying it out
Constants and variables
Loops
Compound data
Enums and pattern matching
Struct methods
Using other pieces of code in your module
Sequences
Exercise - fix the word counter
Summary
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
Unit Testing and Benchmarking
Motivation and high-level view
Annotations
Assert macros
Integration or black box tests
Documentation tests
Benchmarks
Integrating with Travis
Founding a city-builder game
Final exercise - fixing the tests
Summary
Types
String types
String slices
The String type
Byte strings
Takeaways and tasks
Arrays and slices
Takeaways and tasks
Generic types
Takeaways and tasks
Traits and implementations
Takeaways and tasks
Constants and statics
Summary
Error Handling
Option and Result
Unwrapping
Mapping of the Option/Result values
Early returns and the try! macro
The ? operator
Panicking
Custom errors and the Error trait
Exercise
Summary
Memory, Lifetimes, and Borrowing
LLVM
Function variables and the stack
The heap
Memory safety
Ownership
Copy trait
Function parameters and patterns
Borrowing
Lifetimes
Globals
References as function parameters
Structs and struct fields
Impl signatures
The Drop trait
Collector types
Box<T>
Interior mutability for Copy types - Cell<T>
Interior mutability for move types - RefCell<T>
Practical uses of interior mutability
Reference collected memory: Rc<T> and Arc<T>
Inspecting memory usage with std::mem
Final exercises
Summary
Concurrency
Problems with concurrency
Closures
Exercises
Threads
Exercises
Sharing the Copy types
Channels
Exercises
Locks and mutexes
Exercises
Atomic Rc
Exercises
The final exercise
Summary
Macros
Introduction to metaprogramming
Dissecting println!
Exercises
Debugging macros
Macro keywords
block
expr
ident
item
meta
pat
path
stmt
tt
ty
Repeating constructs
Example - an HTTP tester
Exercises
Summary
Compiler Plugins
Basics of compiler plugins
The minimal compiler plugin
Building a compiler plugin via Cargo
Code generation as a workaround
Aster
Linter plugins
Macros 1.1 - custom derives
Exercises
Summary
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
Parsing and Serialization
Parsing fundamentals
nom
Chomp
Other parser libraries
Serde
Exercises
Summary
Web Programming
Introduction to Rust and web programming
Hyper as a client
Hyper as a server
Rocket
Other web frameworks
Exercises
Summary
Data Storage
SQLite
PostgreSQL
Connection pooling with r2d2
Diesel
Summary
Debugging
Introduction to debugging
GDB - basics
GDB - threads
LLDB - quick overview
Editor integration with Visual Studio Code
Exercises
Summary
Solutions and Final Words
Chapter 1 - Getting Your Feet Wet
Exercise - fix the word counter
Chapter 2 - Using Cargo to Build Your First Program
Exercise - starting our project
Chapter 3 - Unit Testing and Benchmarking
Exercise - fixing the tests
Chapter 4 - Types
Exercise - various throughout the chapter
Chapter 5 - Error Handling
Exercise solutions
Chapter 6 - Memory, Lifetimes, and Borrowing
Exercises
Chapter 7 - Concurrency
Exercises
Chapter 8 - Macros
Exercises
Chapter 9 - Compiler Plugins
Exercises
Chapter 10 - Unsafety and Interfacing with Other Languages
Exercises
Chapter 11 - Parsing and Serialization
Exercises
Chapter 12 - Web Programming
Exercises
Chapter 13 - Data Storage
Chapter 14 - Debugging
Exercises
← Prev
Back
Next →
← Prev
Back
Next →