Mastering Rust 9781785881374, 178588137X, 978-1-78588-530-3, 1483863182

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

480 57 5MB

English Year 2017

Report DMCA / Copyright

DOWNLOAD FILE

Mastering Rust
 9781785881374, 178588137X, 978-1-78588-530-3, 1483863182

Table of contents :
Content: Cover
Copyright
Credits
About the Author
About the Reviewer
www.PacktPub.com
Table of Contents
Preface
Chapter 1: 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
Chapter 2: Using Cargo to Build Your First Program
Cargo and crates
Founding a project --
cargo init. Dependencies, building, and runningRunning 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
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
Chapter 4: Types
String types
String slices
The String type
Byte strings
Takeaways and tasks
Arrays and slices
Takeaways and tasks
Generic types. Takeaways and tasksTraits and implementations
Takeaways and tasks
Constants and statics
Summary
Chapter 5: 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
Chapter 6: 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 traitCollector types
Box
Interior mutability for Copy types --
Cell
Interior mutability for move types --
RefCell
Practical uses of interior mutability
Reference collected memory: Rc and Arc
Inspecting memory usage with std::mem
Final exercises
Summary
Chapter 7: 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
Chapter 8: Macros
Introduction to metaprogramming
Dissecting println!
Exercises. Debugging macrosMacro keywords
block
expr
ident
item
meta
pat
path
stmt
tt
ty
Repeating constructs
Example --
an HTTP tester
Exercises
Summary
Chapter 9: 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
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.

Polecaj historie