
- 354 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Mastering Rust
About this book
Discover the powerful, hidden features of Rust you need to build robust, concurrent, and fast applicationsAbout This Book• Learn how concurrency works in Rust and why it is safe• Get to know the different philosophies of error handling and how to use them wisely• After reading this book, you will be able to migrate your legacy C or C++ application to a Rust environmentWho This Book Is ForThe target audience would be readers having knowledge of other programming languages and are able to work fluently in the operating system of their choice, be it Linux, OS X or Windows. Since Rust is a rather new language, they are interested in programming beyond simply using it for work. The book focuses on intermediate and advanced features of Rust.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 abstractionsIn DetailIf 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.Style and approachThis book is your one stop guide to the Rust programming language and covers advanced-level concepts in a detailed manner using real-world examples.
Tools to learn more effectively

Saving Books

Keyword Search

Annotating Text

Listen to it instead
Information
Solutions and Final Words
Chapter 1 - Getting Your Feet Wet
Exercise - fix the word counter
use std::env;
use std::fs::File;
use std::io::prelude::BufRead;
use std::io::BufReader;
use std::collections::HashMap;
#[derive(Debug)]
struct WordStore (HashMap<String, u64>);
impl WordStore {
fn new() -> WordStore {
WordStore (HashMap::new())
}
fn increment(&mut self, word: &str) {
let key = word.to_string();
let count = self.0.entry(key).or_insert(0);
*count += 1;
}
fn display(&self) {
for (key, value) in self.0.iter() {
println!("{}: {}", key, value);
}
}
}
fn main() {
let arguments: Vec<String> = env::args().collect();
println!("args 1 {}", arguments[1]);
let filename = arguments[1].clone();
let file = File::open(filename).expect("Could not open file");
let reader = BufReader::new(file);
let mut word_store = WordStore::new();
for line in reader.lines() {
let line = line.expect("Could not read line");
let words = line.split(" ");
for word in words {
if word == "" {
continue
} else {
word_store.increment(word);
}
}
}
word_store.display();
}
Chapter 2 - Using Cargo to Build Your First Program
Exercise - starting our project
- Initialize a Cargo binary project, call it whatever you want (but I will name the game fanstr-buigam, short for fantasy strategy building game).
cargo init fanstrbuigam -bin
- Check cargo.toml and fill in your name, e-mail, and description of the project.
- Try out the Cargo build, test, and run commands.
Chapter 3 - Unit Testing and Benchmarking
Table of contents
- Title Page
- Copyright
- Credits
- About the Author
- About the Reviewer
- www.PacktPub.com
- Preface
- Getting Your Feet Wet
- Using Cargo to Build Your First Program
- Unit Testing and Benchmarking
- Types
- Error Handling
- Memory, Lifetimes, and Borrowing
- Concurrency
- Macros
- Compiler Plugins
- Unsafety and Interfacing with Other Languages
- Parsing and Serialization
- Web Programming
- Data Storage
- Debugging
- Solutions and Final Words
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app