Rust in Action
Tim McNamara
  • MEAP began July 2017
  • Publication in December 2018 (estimated)
  • ISBN 9781617294556
  • 400 pages (estimated)
  • printed in black & white

The easiest way to learn Rust I've ever seen!

William E. Wheeler

Rust in Action introduces the Rust programming language by exploring numerous systems programming concepts and techniques.You'll be learning Rust by delving into how computers work under the hood. You'll find yourself playing with persistent storage, memory, networking and even tinkering with CPU instructions. The book takes you through using Rust to extend other applications and teaches you tricks to write blindingly fast code. You'll also discover parallel and concurrent programming. Filled to the brim with real-life use-cases and scenarios, you'll go beyond the Rust syntax and see what Rust has to offer in real-world use cases.

Table of Contents detailed table of contents

1. Introducing Rust

1.1. What is Rust?

1.1.1. Safety

1.1.2. Ergonomics

1.1.3. Control

1.2. Rust’s Big Features

1.2.1. Performance

1.2.2. Concurrency

1.2.3. Memory Efficiency

1.3. Downsides of Rust

1.3.1. Compile Times

1.3.2. Strictness

1.3.3. Size of the Language

1.3.4. Hype

1.3.5. Single Implementation

1.4. Where Rust Fits

1.4.1. Data Processing

1.4.2. Extending an Application

1.4.3. Operating in Resource-constrained Environments

1.4.4. Applications

1.4.5. Systems Programming

1.5. Rust’s hidden feature: its community

1.6. A Taste of the Language

1.6.1. Cheating Your Way To "Hello, world!"

1.6.2. Your First Rust Program

1.7. Summary

Part 1: Just Enough Rust

2. Language Foundations

2.1. A Glance at Rust’s Syntax

2.1.1. A whole program with main()

2.2. Starting out With Numbers

2.3. Type-aware control flow with match

2.4. Getting Stuff Done With Functions

2.5. Advanced Function Definitions

2.5.1. Explicit Lifetime Annotations

2.5.2. Generic Functions

2.6. Creating grep-lite v1

2.7. Making Lists of Things with Arrays, Slices and Vectors

2.7.1. Arrays

2.7.2. Slices

2.7.3. Vectors

2.8. Including Third Party Code

2.8.1. Adding Support for Regular Expressions

2.8.2. Generating Crates' Documentation Locally

2.8.3. Managing Rust toolchains with rustup

2.9. Supporting Command Line Arguments

2.10. Reading From Files

2.11. Reading from STDIN

2.12. Summary

3. Compound Data Types

3.1. Using plain functions to experiment with an API

3.2. Modeling Files With struct

3.3. Adding Methods to a struct with impl

3.3.1. Simplifying object creation by implementing a new() method

3.4. Returning errors

3.4.1. Modifying a known global variable

3.4.2. Making use of the Result return type

3.5. Defining and making use of enum

3.5.1. Using an enum to manage internal state

3.6. Defining Common Behavior with Traits

3.6.1. Creating a Read trait

3.6.2. Implementing Display for your own types

3.7. Exposing your types to the world

3.7.1. Protecting private data

3.8. Creating In-line Documentation

3.8.1. Using rustdoc to Render Docs For a Single Source File

3.8.2. Using cargo to Render Docs for a Crate and its Dependencies

3.9. Summary

4. Lifetimes, Ownership and Borrowing

4.1. “Implementing” a Mock CubeSat Ground Station

4.1.1. Encountering our first lifetime issue

4.1.2. Special behavior of primitive types

4.2. Guide to the figures in this chapter

4.3. What is an Owner? Does it Have any Responsibilities?

4.4. How Ownership Moves

4.5. Resolving Ownership Issues

4.5.1. Use references where full ownership is not required

4.5.2. Use Fewer Long-Lived Values

4.5.3. Duplicate the value

4.5.4. Wrap Data Within Specialty Types

4.6. Summary

Part 2: Programming from the Ground Up (Almost)

5. Data in Depth

5.1. Bit Patterns and Types

5.2. Life of an integer

5.2.1. Understanding Endianness

5.3. Decimal Numbers

5.3.1. About Floating Point

5.3.2. Looking inside an f32

5.3.3. Representing decimal numbers in a single byte with a fixed-point number format

5.4. Generating f32 values between 0 and 1 from random bytes

5.5. Implementing a CPU in Software to Establish that Functions are also Data

5.5.1. CPU 1: “the Adder”

5.5.2. First working emulator

5.5.3. CPU 2: “the Multi-Adder”

5.5.4. CPU 3: Adding functions

5.5.5. CPU 4: Adding the rest

5.6. Summary

6. Memory

6.1. Pointers

6.1.1. Raw pointers in Rust

6.1.2. Rust’s pointer ecosystem

6.1.3. Smart pointer building blocks

6.2. Providing programs with memory for their data

6.2.1. The stack

6.2.2. The heap

6.2.3. What is dynamic memory allocation?

6.3. Virtual Memory

6.3.1. Background

6.3.2. Step 1: Having a Process Scan Its Own Memory

6.3.3. Translating virtual addresses to physical addresses

6.3.4. Step 2: Working with the operating system to scan an address space

6.3.5. Step 3: reading and writing bytes to processes' memory

6.4. Wrap up

7. Files

8. Hashing

9. Trees

10. Networking

Part 3: Concurrent and Parallel Programming

11. Time and Time Keeping

11.1. Background

11.2. Sources of Time

11.3. Definitions

11.4. Encoding Time

11.4.1. Representing time zones

11.5. clock v0.1.0: Teaching an application how to tell the time

11.5.1. clock v0.1.1: Formatting timestamps to comply with ISO 8601 and email standards

11.5.2. Refactoring the clock v0.1.0 code to support wider architecture

11.5.3. Formatting the time as a UNIX timestamp or a formatted string according to ISO 8601, RFC 2822, and RFC 3339

11.5.4. Providing a full command-line interface

11.5.5. The full clock v0.1.1 code listing

11.6. clock v0.1.2: Setting the time

11.6.1. Common behavior

11.6.2. Setting the time in operating systems that use libc

11.6.3. Setting the time on MS Windows

11.6.4. clock v0.1.2 Full code listing

11.7. Improving error handling

11.8. clock v0.1.3 Resolving differences between clocks with the Network Time Protocol (NTP)

11.8.1. Sending NTP requests and interpreting responses

11.8.2. Adjusting the local time as a result of the server’s response

11.8.3. Converting between time representations that use different precisions and epochs

11.8.4. clock v0.1.3 full code listing

11.9. Summary

12. Signals & Interrupts

Part 3: Concurrent and Parallel Programming

13. Creating a Distributed Graph

14. Sharing Resources with Locks

15. Sharing Resources with Atomic Operations

About the Technology

Rust is a new systems programming language that gives you the low-level power of C with the elegance and ease of languages like Ruby and Python. Rust is thread safe, enabling "fearless concurrency". Threads are guaranteed not to overwrite each others' data, but it doesn't impose a garbage collector on you, keeping runtime performance predictable. It incorporates features from functional programming such as higher-order functions that allow for compact, readable programs. Rust is perfect for developers who want to fearlessly explore systems programming with a more ergonomic, less intimidating alternative to C or C++.

What's inside

  • Portability with Rust
  • Concurrent and parallel programming
  • Sharing resources with locks or atomic operations
  • Avoiding programming with global state
  • Message passing inside your applications
  • Memory management and garbage collection

About the reader

Readers need intermediate programming skills and familiarity with general computer science concepts, the command line, and networking.

About the author

Tim McNamara is an experienced programmer with a deep interest in natural language processing, text mining, and wider forms of machine learning and artificial intelligence. He is very active in open source communities including the New Zealand Open Source Society.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
buy
MEAP combo $44.99 pBook + eBook + liveBook
MEAP eBook $35.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks

Densely packed but very approachable, anyone with previous programming experience will find this book an excellent introduction to Rust.

Morgan Nelson