index

Symbols

? operator 88, 123, 212

& operator 96

Numerics

0.0.0.0 address 184

A

Actix framework 183

align property 113

all() function 117

all() predicate 57

all(predicated) attribute 21

alloc-cortex-m crate 42

allocate() method 111, 113

allocated_zeroed() method 111

Allocator API 110

Allocator trait 110111, 114

allocator_api 57

allow() attribute 54

any() function 117

any() predicate 57

any(predicate) attribute 21

anyhow crate 216

API client

deciding which tools and libraries to use 205206

designing CLI 206207

API service

API design 184185

creating architecture 184185

APIs (application programming interfaces)

declaring routes 194195

implementing API routes 195197

application scaffolding 187190

init_dbpool() function 189190

init_tracing() function 188

main() function 187188

arbitrary crate 152

Arc 104106, 131

architecture, creating 184185

args argument 148

arrays 6972

as_mut() method 96

as_ref() method 96

AsMut trait 96

AsRef trait 96

assert_cmd crate 147149

assert_eq!() macro 143

assert!() macro 143

assert2 crate 125

async fn syntax sugar 169

async keyword 164

async programming, thinking asynchronously 159160

async Rust 157181

concurrency and parallelism with 166169

futures, handling async task results 161164

implementing observers 169174

keywords 164166

mixing sync and async 174176

testing async code 180181

#[tokio::main] 164

tracing and debugging async code 177180

when and where to use 164166

when to avoid using 176180

asynchronous I/O 3

avx2 target feature 117

.await feature 169

.await keyword 164166

axum framework 183

axum::extract::FromRequest trait 196

axum::extract::FromRequestParts trait 196

axum::extract::Json 196

axum::extract::Path 196

axum::extract::State 196

axum::response::IntoResponse trait 197

B

binary distribution 2931

building statically linked binaries 3031

cross compilation 30

BinaryHeap 74

bindgen tool 29

blacklisted_name lint 52

blocking sleep 168

body field 194

bool_comparison lint 52

borrow checker 3, 9697

borrowing 96

Box 72, 104

smart pointers 100103

Box data structure 95

broadcast channel 176

BTreeMap 74

BTreeSet 74

build command 15

build time operations 40

build_hasher() method 76

BuildHasher API 76

built-in integration testing 146150

libraries and tooling 147150

assert_cmd 147149

proptest 149

C

calloc() method 111

caret operator 17

Cargo 3

basic usage 1213

binary distribution 2931

building statically linked binaries 3031

cross compilation 30

building, running, and testing 1415

creating new application or library 1314

dependency management 1619

handling Cargo.lock file 1819

- -lib argument 14

linking to C libraries 2729

modules 3537

patching dependencies 2124

best practices for 2324

indirect dependencies 23

project management with

custom building scripts 4041

feature flags 1921

publishing crates 2427

CI/CD integration 2427

- -release flag 220

rerun-if-changed 40

switching between toolchains 1516

tour of 1216

workspaces 3839

cargo add command 17

cargo doc command 42

cargo expand 132

cargo new command 14

cargo-expand 5960

cargo-fuzz 60

cargo-fuzz crate 151

cargo-tree 6162

cargo-update 59

cargo-watch 6061

Cargo.lock file 1819

carrying_add() function 127

cc crate 40

CD (continuous deployment) 24

Cell type 105

cfg attribute 20, 57, 116117

cfg macro 116117

cfg(predicate) attribute 21

changing ecosystem 140

checked_add() function 127

checked_div() method 80

CI (continuous integration) 24

CI/CD integration 2427

clang 233

clang-format tool 51

CLI (command-line interface)

assert_cmd 147149

testing 212214

client—server relationship 204

Clippy 4455, 234

automatically applying suggestions 54

+channel option 15

- -check option 49

configuring 5354

- -fix flag 54

installing 51

lints 5253

using in CI/CD 5455

clone on write 107109

Clone trait 98, 107108

clone() method 98, 107

closures 3

code coverage 139

Codecov 139

#[command] macro 207

commands

declaring 207209

implementing 209210

Commands enum 209210

CommonMark 33

compile_error!() macro 122

components

installing HTTPie 235

installing rustc and other components 234

managing with rustup 234235

switching default toolchains with rustup 234

compress() function 2728

compressBound function 28

concurrency 157, 166169

const generics 70

Context type alias 86

copies, avoiding 99100

copy constructors 96

Copy trait 107

copy_from_slice() method 71

COUNT variable 130

Coveralls 139

Cow (clone on write) trait 107

crates.io 3

CreateTodo struct 193

cross compilation 30

CRUD (create, read, update, delete) 184

custom allocators 110117

creating for protected memory 113117

writing 110113

D

data modeling 190194

interfacing with data 191194

SQL schema 190191

data structures 6566

error handling with Result enum 8788

maps 76

Result enum 8788

slices and arrays 6972

strings 6669

String vs. str 6667

using effectively 6769

vectors 74

types related to 74

Vec 73

wrapping 7374

DATABASE_URL environment variable 189

deallocate() method 111, 113

Debug trait 76

debugging

async code 177180

macros with cargo-expand 5960

deep copying 9798

dependency management 1619

handling Cargo.lock file 1819

Deref trait 72

DerefMut trait 72

#[derive] attribute 76

derive macro 207

#[derive(Clone)] attribute 98

destructures 70

doc attribute feature 58

doc compiler attribute 57

doc keyword 58

doc_cfg 57

doctest keyword 58

documentation, code examples in 3435

doubly linked list 105

Drop trait 68

dryoc crate 19, 55, 86, 114

dyn Trait syntax 220

E

ecosystem, changing 140

embedded environments 4142

memory allocation 42

summary 42

Embedded Rust Book, The 42

enums 86

Eq trait 76

Error enum 197

error handling 197198

with Result enum 8788

errors, handling gracefully 212

expect() function 123

expected result 148

external integration testing 146150

libraries and tooling 147150

assert_cmd 147149

proptest 149

extractors 196

F

feature flags 1921

FFI (foreign function interface) 27, 230

handling compatibility with Rust’s types 9092

File:open function 88

fill_with() function 71

fill() function 71

finish() method 76

fixtures 148

for_loop() method 224

free() function 110112

From implementation 88

From trait 84, 123, 193, 197, 212

“full” feature flag 181

Future trait 164, 170171, 183

futures, handling async task results 161164

#[tokio::main] 164

futures::future::join_all( ) function 167

fuzz subdirectory 151

fuzz testing 60153

G

generics 3

GlobalAlloc API 110

GlobalAlloc trait 42

H

Hash trait 76

Hasher API 76

HashMap 7476, 137

creating hashable types 76

custom hashing functions 7576

HashSet 74

heapless crate 42

heaps 9496

help command 207

Homebrew, installing tools using 233

HTTP REST API (application programming interface) CLI 204205

deciding which tools and libraries to use 205206

declaring commands 207209

designing CLI 206207

handling errors gracefully 212

implementing commands 209210

requests 210211

testing 212214

HTTP REST API service

API design 184185

application scaffolding 187190

init_dbpool() function 189190

init_tracing() function 188

main() function 187188

building

data modeling 190194

error handling 197198

creating architecture 184185

declaring API routes 194195

implementing API routes 195197

libraries and tools 185187

running 198202

web frameworks 183

HTTPie, installing 199, 235

Hyper 183

I

IDEs (integrated development environments)

integration with 5658

nightly channel 5758

nightly only features 5758

using nightly on published crates 58

toolchains 5758

stable vs. nightly 5758

VS Code 5658

impl keyword 83

init_dbpool() function 189190

init_tracing() function 188

integration testing 141153

external vs. built-in 146150

libraries and tooling 147150

fuzz testing 153

libraries and tooling 147150

overview 144146

testing strategies 144146

interior mutability 105

Into trait 193

into_iter() method 223224

isize identifier 79

iter() method 223

iterating

cargo-tree 6162

cargo-watch 6061

J

join() function 229

jq tool 206

K

Key type alias 86

L

languages, other, using Rust to accelerate 229230

Layout struct 113

lazy_static! macro 132

libc crate 40

libc dependency 28

libFuzzer library 150

libraries and tools 185187

libtest 129

link attribute 28

linked lists, smart pointers 100103

LinkedList 74

linking to C libraries 2729

lints 5253

Linux, installing rustup on 233234

LLDB (Low Level Debugger) 43

LLVM (Low Level Virtual Machine) 4243

lowercased() function 100

M

macOS, installing tools using Homebrew 233

macros 3, 164, 180, 207

debugging with cargo-expand 5960

magic completions 4647

main() function 14, 40, 129, 143, 164, 168, 187188, 212

make_mut() method 107

malloc() function 95, 110112

maps 76

creating hashable types 76

custom hashing functions 7576

McNamara, Tim 231

memcpy() function 71

memory

avoiding copies 99100

clone on write 107109

custom allocators 110117

creating for protected memory 113117

writing 110113

deep copying 9798

ownership 9697

borrow checker 9697

copy constructors 96

enforcing 9697

memory allocation 42

memory management

heap and stack 9496

reference counting 104106

smart pointers 100103

summarized 117118

memset() function 71

mlock() function 114

mod keyword 35

mod statement 37

modules 3537

monad 101

mprotect() function 114

mpsc channel 176

mut keyword 96

Mutex 105, 131

N

new keyword 95

new() method 101

nightly channel

nightly only features 5758

using nightly on published crates 58

not() function 117

not(predicate) attribute 21

O

Observable trait 172173

observe() method 170

Observer trait 171172

observers, implementing in async Rust 169174

oneshot channel 176

optimizations 219232

SIMD (single instruction, multiple data) 226227

using Rust to accelerate other languages 229230

vectors 226

fast copies with Vec and slices 225226

iterators 223224

memory allocation 221223

where to go from here 231

zero-cost abstractions 220

Option 101103

overflowing_add() function 127

override option 16

ownership 9697

P

panic!() macro 122

parallelism 158, 166169

parallelization, with rayon 227229

parameterized crate 125

parse() method 153

PartialEq trait 76

partition() function 142, 144

patching dependencies 2124

best practices for 2324

indirect dependencies 23

ping() function 195

poll() method 164, 171

posix_memalign() function 114

primitive types 7780

arithmetic on primitives 7980

integer types 7778

size types 79

println completion 47

println!() function 165

project management

documenting Rust projects 3135

code examples in documentation 3435

linking to C libraries 2729

with Cargo

custom building scripts 4041

feature flags 1921

proptest crate 125, 149

proptest! macro 126

protected memory 113117

protected module 58

protoc-rust 40

ptr::copy_nonoverlapping() function 71

pub keyword 36

publishing crates 2427

CI/CD integration 2427

Q

QEMU project 42

QuickCheck 125

quicksort algorithm 142

quicksort() function 142, 145

R

RAII (resource acquisition is initialization) 4

rayon crate, parallelization with 227229

read_to_string() function 88

realloc() method 111

redundant_clone lint 53

RefCell type 105

reference counting 104106

references 96

#[repr(C)] attribute 90

request() function 210

requests 210211

reqwest library 205

REST API service

application scaffolding 187190

building, data modeling 190194

declaring API routes 194195

implementing API routes 195197

Result 129

Result enum 8788

rewriting 137138

Rocket framework 183

Router 194

RowNotFound case 198

rstest crate 125

ruduino crate 42

runtime, with #[tokio::main] 164

Rust 18

documenting projects 3135

overview 23

projects in embedded environments 4142

memory allocation 42

summary 42

rust-analyzer 4547

magic completions 4647

tools 8

additional 5862

unique features of 46

modern 5

open source 56

safety 45

vs. other popular languages 6

use cases 78

Rust Design Patterns (Matthews) 231

Rust in Action (McNamara) 231

Rust language website 6

rust-analyzer 3, 4447, 135

magic completions 4647

rust-bindgen tool 91

rust-clippy 3

rustc 3, 12

managing with rustup 234235

installing HTTPie 235

installing rustc and other components 234

switching default toolchains with rustup 234

rustc compiler 4, 4243, 51

rustc wrapper 55

RUSTC_WRAPPER argument 55

rustdoc attribute 58

rustdoc tool 31

RUSTFLAGS environment variable 31

rustfmt 3, 44, 4951, 234

configuring 5051

installing 50

rustup 56

installing on Linux- or UNIX-based systems 233234

managing rustc and other Rust components with 234235

installing HTTPie 235

installing rustc and other components 234

switching default toolchains with rustup 234

rustup toolchain install nightly command 16

RwLock 105, 131

S

safety, Rust 45

saturating_add() function 127

sccache tool 3, 44, 5556

configuring 56

installing 55

scripts, custom building 4041

select( ) system call 167

self parameter 99, 171

semantic versioning (SemVer) 17

semver crate 18

Send trait 104, 130131

SIMD (single instruction, multiple data) 226227

size property 113

size() method 112

sleep() function 162

slices 6972

fast copies with Vec and 225226

smart pointers 100103

summarized 117118

snippets 46

split_at() function 70

SQL schema 190191

sqlx-cli tool 186

src directory 13

stack 95

stacks 9496

'static lifetime specifier 67

static typing 3

std::collections::LinkedList 103

std::default::Default 75

std::hash::BuildHasher 75

std::hash::Hasher 75

std::io::Error type 88

std::simd module 226

std::span 69

std::string_view 69

std::sync::Once primitive 133

strings 6669

String vs. str 6667

using effectively 6769

strndup() function 67

structs 83

structural search and replace tool 135

swap() function 81

sync module 176

sync Rust, mixing sync and async 174176

Sync trait 104, 131

T

TDD (test driven development) 144

#[test] attribute 143

test-case crate 125

"test-util" feature 181

testing

fuzz testing 60

review of built-in testing features 124125

unit testing

handling parallel test special cases and global state 129134

what not to test 129134

testing async code 180181

testing frameworks 125128

tfn completion 47

thiserror crate 216

time command 15

tmod completion 47

to_lowercase() function 100

Todo struct 191

#[tokio::main] 164

#[tokio::test] macro 180

tokio_test crate 181

TOKIO_WORKER_THREADS environment variable 188

tokio::join!( ) function 167

tokio::main macro 188

tokio::runtime::Handle 180

tokio::runtime::Handle::block_on() method 166

tokio::select!( ) macro 167

tokio::spawn( ) function 168

tokio::sync::mpsc module 176

tokio::task::spawn_blocking() function 166, 175

tokio::task::spawn() function 164168

TOML (Tom’s obvious, minimal language) 13

too_many_arguments warning 53

toolchains 15

+channel option 15

stable vs. nightly 5758

tooling 4362

additional tools 5862

cargo-expand 5960

cargo-fuzz 60

cargo-tree 6162

cargo-update 59

cargo-watch 6061

Clippy 55

automatically applying suggestions 54

configuring 5354

installing 51

lints 5253

using in CI/CD 5455

IDEs (integrated development environments)

integration with 5658

nightly channel 5758

toolchains 5758

VS Code 5658

overview of 44

rustfmt 4951

configuring 5051

installing 50

tooling: rustfmt (continued)

sccache tool 5556

configuring 56

installing 55

tools 8

installing for this book 233234

on Linux- or UNIX-based systems 233234

on macOS using Homebrew 233

on Windows 234

refactoring 134139

Tower library 183

#[tracing::instrument] macro 177

tracing async code 177180

traits 3

try_new() method 101

tuple struct 82

tuples 8081

types 77

enums 86

handling FFI compatibility with 9092

primitive types 7780

arithmetic on primitives 7980

integer types 7778

size types 79

structs 83

tuples 8081

U

unchecked_add() function 127

uncompress() function 2728

unit struct 82

unit testing 121140

code coverage 139

dealing with changing ecosystem 140

differences in Rust 122123

handling parallel test special cases and global state 129134

refactoring 134138

tools 134138

review of built-in testing features 124125

testing frameworks 125128

what not to test 129134

unix configuration predicate 117

UNIX-based systems, installing rustup on 233234

unsafe keyword 67, 111, 113, 122

unwrap() function 129

update() method 172

UpdateTodo struct 193

use statements 3536

usize identifier 79

UX (user experience) 144

V

Vec 73

Vec data structure 95

Vec::copy_from_slice() method 225

Vec::shrink_to_fit() method 223

VecDeque 74

vectors 74, 226

fast copies with Vec and slices 225226

iterators 223224

memory allocation 221223

types related to 74

Vec 73

wrapping 7374

VirtualAlloc() function 114

VirtualLock() function 114

VirtualProtect() function 114

VS Code (Visual Studio Code) 5658

features of 5658

integration with 5658

vtables 220

W

Wasm (WebAssembly) 2

watch channel 176

web frameworks 183

windows configuration predicate 117

Windows Subsystem for Linux (WSL) 234

Windows, installing tools on 234

workspaces 3839

Wrapping struct 127

wrapping_add() function 127

WrappingAdd trait 127128

write() method 76

Y

yield points 163

Z

-Z unstable-options option 54

zero-cost abstractions 220

zlib library 27