index

Symbols

_ wildcard 465

? operator 118, 407, 474

.. two dots 55

* (asterisk) 469

&str type 3032, 128, 149151, 189, 342, 434

#![no_std] attribute 269

#[cfg] attribute 269

#[deprecated] attribute 269

#[derive(Error)] attribute 360

#[derive] attribute 423

#[error] attribute 360

#[non_exhaustive] attribute 269, 449

+ operator 129

A

Add trait 129, 421

and other similar traits 420423

Add variant 299

AddAssign trait 422

adds_hungary function 4142

.all() method 177, 234

allocating memory, const and static 33

.and_hms_opt() method 350

.and_then() method 175

.and() method 175176

angle brackets 91

annotations. See lifetime annotations

anonymous functions 161168

closures

|_| in 167

inside of methods 163164

lazy and fast 164167

anonymous lifetime 195199

ansi_term crate 486

Any trait 444

.any() method 177, 295

anyhow crate 357360, 490

anyhow! macro 358

App struct 485, 490

App trait 513

.append() method 390

Arc (atomic reference counter) 233, 249250, 252, 260

architecture 9

Args struct 382

args() method 383

argue_in_court() function 141

arguments 16, 466

closures as 234244

example 242244

relationship between FnOnce, FnMut, and Fn 239

simple closures 237239

uniqueness of closures 240

arrays 5355, 413417

destructuring and mapping 414

implementing Iterator 413

using from_fn to make 415417

.as_bytes() method 13

.as_micros() method 357

.as_nanos() method 357

ASCII 9, 47

AsRef trait 149151

assert_eq! macro 123, 156, 289290

assert_eq!() macro 416

assert_ne! macro 123

assert! macro 123, 290

Assign trait 422

associated items and associated constants 424428

associated consts 427

associated functions 81, 425

associated types 158, 425

async block 406

async main 405

async Rust 402410

basics of 402

checking whether Future is ready 403

feature flags 399402

other details about 407410

using async runtime 405407

async_trait crate 410

AsyncIterator trait 410

atomic types 249

AtomicI64 type 249

AtomicU64 type 249

attributes 81, 129, 265271, 289, 360, 423, 449

available_parallelism() method 355

.await keyword 403, 405406

axum_sessions crate 512

B

b prefix 54

Backtrace struct 449

Backtrace::capture() function 447

backtraces 447450

BacktraceStatus enum 449

.bark() method 131

basics

floats 15

printing 22

BigBuffers struct 325

BinaryHeap 115

blanket trait implementations 33, 134, 341, 362366

Block widget 493, 499

blocking Client (reqwest crate) 399

BookCollection struct 158159

bool 390, 428

bounds, traits as 140142

Box 261, 271281

basics of 271273

downcasting to concrete type 279281

handling multiple error types 276279

putting around traits 273276

Box<dyn Error> 490

BTreeMap 107108

BTreeSet 113

Buffers struct 325

builder pattern 303, 307314

adding final check to 309

builder methods 307

Deref 314322

basics 314

implementing 316

using wrong way 320322

DerefMut 318

final check to 309

making more rigorous 313

writing builder methods 307

.by_ref() method 182

byte array 54

C

.capacity() method 57

Cargo 374380

compiling with 376380

reasons for using 374376

cargo add command 380

cargo add reqwest command 399

cargo build --release 445

cargo build --timings command 380

cargo clean command 380

cargo clippy command 380

cargo doc 392394

cargo new command 375

cargo run --release 445

Cargo.toml file and external crates 336

casting enums into integers 78

.ceil() method 423

Cell 200

cfg attribute 269

cfg! macro 458460

chaining methods 153

.change_city_data() method 242, 244

channel() function 256

channels 256260

basics 256

implementing 257260

char type 9, 417

characters 714

.chars() method 13, 295

.chars().count() method 13

check_book_type() function 213

check_guess() function 507

checked operations 419

.checked_ methods 420

.checked_add() method 419420

.checked_div() method 419

.checked_mul() method 419

.checked_sub() method 317, 419

chrono crate 344354, 495

checking code inside external crates 350

.chunks() method 183

City struct 84

ClearType enum 484

CLIs (command-line interfaces) 481

Clone trait 44, 92, 128

.clone() method 265

.cloned() method 182

cloning on write 215219

closures 170185, 233

|_| in 167

as arguments 234244

example 242244

relationship between FnOnce, FnMut, and Fn 239

simple closures 237239

uniqueness of closures 240

checking 177180

filtering 170173

finding items inside 177180

inside iterators 161168

inside of methods 161168

lazy and fast 164167

mapping 170173

methods 174185

related methods 174185

code

keeping clean with macros 475479

code blocks 17

declaring variables 20

.collect() method 153, 156, 164, 414

collection types 5360, 106117

arrays 5355

BinaryHeap 115

HashMap 107108

.entry() method 110113

HashSet 113

tuples 5860

VecDeque 117

vectors 5558

Color 32 522

column! macro 454

command-line arguments 382385

command-line interfaces (CLIs) 481

comments 67

Company struct 170, 172

compare_and_display() function 94

complex examples 135140

concrete &self 136

concurrency 251

const 33, 323326

const functions 326328, 366

mutable statics 328

const functions 326328, 366

const generics 145, 324326

const keyword 325

const values 324

ConstParam 324

control flow 6070

basic 60

loops 6670

match statements 6165

copy semantics 42

Copy trait 92, 128, 135

Copy types 28, 4245, 51, 438

.count() method 13

Country struct 73, 421

Cow type 209, 215219, 342

crates 283289, 341

error handling 357362

Anyhow 358359

thiserror 360362

external 335339

and Cargo.toml 336

rolling dice with rand crate 337339

using rand crate 336

module 286

Rayon 354357

reqwest crate 397399

time crate 344349

.create_new() method 390

.create() method 390

CreationContext 513

Crossterm 481, 487

CString type 412, 434

curly brackets 253

.cycle() method 180

cycling 180185

D

DateTime struct 495

dbg! macro 169, 472473

Debug mode 377378

Debug printing 22

Debug trait 92, 128, 132, 138, 363

.debug_struct() method 278

.dedup() method 430

Default trait 303

Deref 149, 190, 302303, 314322

basics 314

implementing 316

using wrong way 320322

DerefMut 318

implementing 304306

.delete_book() function 212213

deprecated attribute 270

dereferencing 36, 87

Deserialize attribute 342343

Deserialize trait 489

.desired_width() method 524

destructuring 60, 8387

destructuring arrays 414

directory and file navigator 520527

developing code 522524

further development and cleanup 524526

setup and first code 521

DirectoryContent enum 527

DirEntry 521

Display printing 22

Display trait 92, 94, 132135, 325, 478

.display_self() method 138139

Div trait 422

DivAssign trait 422

diverging code 103

.do_operation() method 300

doc comments (documentation comments) 7

documentation

cargo doc 392394

reading 262271

[src] button 264

assert_eq! 262

attributes 265271

searching 264

traits 265

dot operator 87

.downcast_mut() method 279

.downcast_ref() method 279, 281, 444

.downcast() method 279

downcasting 279

.drain() method 431

.draw() method 493

drop() function 206, 273, 431, 437438

.duration_since() method 348

dyn keyword 275

dynamic dispatch 275

dynamically sized types 31, 216

E

eframe crate 513

eframe::run_native() method 513

egui crate 512

egui web demo 520

.elapsed() method 346, 355

Email type 319

Entry enum 111

.entry() method 110113

.enumerate() method 164, 167

enums 7283

casting into integers 78

implementing 8183

using multiple types 79

env_logger crate 387

environment variables 385387

error attribute 360

error handling 106, 357362

Anyhow 358359

panic hooks 442447

panic! macro 122126

thiserror 360362

Error trait 444

ErrorKind enum 358

escape characters 46

.escape_unicode() method 417

Event enum 482, 501

exclusive range 55

execute! macro 484

ExitStatus 404

Expand button 470

.expect() method 124125, 289

extern crate 451

external crates 323, 335339

and Cargo.toml 336

rolling dice with rand crate 337339

using rand crate 336

ExternalCrateError variant 363

extractors 505

F

f32 423

f64 423

fast closures 164167

fastrand::bool() method 516

feature flags 399402

ffi (foreign function interface) 434

File struct 314

File type 147149

.file_name() method 521

.file_type() method 521

File::create() method 389

File::options() method 390, 392

file! macro 454, 473

files 388392

creating 388

opening existing 389

OpenOptions 389392

.filter_map() method 170

.filter() method 170, 434

filtering 170173

.find() method 179

.flatten() method 176

floats 15, 423

.floor() method 423

.fmt() method 265, 276

fn pointers 327

Fn trait 239, 260

FnMut trait 239, 260

FnOnce trait 229, 231, 239, 260

.fold() method 180, 424

folding 180185

for loop 154

.for_each() method 156, 163, 180

format_args! macro 471

format! macro 32, 360

.format() method 495

formating alignment 49

fragment specifiers 467

French trait 143

From trait 33, 128, 145147, 417

from_fn() method 412, 415417

from_str() method 343

from_utf8() method 101

from_ymd_opt() method 350

from_ymd() method 350

from() method 265

functions

importing and renaming inside 210

lifetimes in 191

functions.rs file 288

Future trait 398, 402

checking whether Future is ready 403

futures crate 410

futures_concurrency crate 410

G

generics 9095, 233, 324

impl Trait 244248

regular generics compared to 244246

returning closures with 246248

Option and Result 95105

.get_article() method 490

.get_book() function 212213

get_res_from_static() function 509

.get() method 102, 175, 265, 369, 397

give_eight() function 326

gives_higher() function 245

GivesOne struct 161

glob operator 286

GLOBAL_LOGGER 366, 370

graphical user interfaces (GUIs) 481

green threads 225

H

HashMap 107108

.entry() method 110113

HashSet 113

heap 2830

Hello, World! example 1620

helper functions 499

high level 70

hms (hour minutes seconds) 350

I

if let 102, 482

if let syntax 527

immutable references 50

imperative style 153

impl block 81, 148

impl Experienced 141

impl keyword 81, 129

impl Lawyer 141

impl Trait 233, 244248, 260

regular generics compared to 244246

returning closures with 246248

types 327

include_str! macro 391

inclusive range 55

incremental compilation 376

infer verb 14

inner attribute 266

.insert(key, value) method 107

Instant struct 495

Instant::now() function 345

integers 714, 419423

Add trait and other similar traits 420423

checked operations 419

interior mutability 189, 199208

Cell 200

Mutex 204206

RefCell 201204

RwLock 207

into_borrowed method 217

.into_iter() method 154, 156, 355

into_owned method 217

.into_string() method 434

.into() method 33, 58

IntoIterator 383

IntoUrl trait 397

io::Result<DirEntry> 521

.is_alphabetic() method 177

.is_none() method 98

.is_some() method 98

isize type 7

Item associated type 157

.iter_mut() method 154, 156, 355

.iter() method 154, 355, 413

Iterator trait 157158, 161

Iterator, arrays implementing 413

iterators 154161, 170185

chaining methods 153

checking 177180

checking and finding items inside 177180

closures

|_| in 167

lazy and fast 164167

closures inside 161168

cycling 180185

filtering 170173

finding items inside 177180

folding 180185

mapping 170173

methods 174185

zipping 180185

J

.join() method 227, 253

JoinHandle 226227

just_makes_an_i32() function 58

K

KeyEvent struct 482483

KoreaJapanUserEvent struct 353

L

lambdas 161

largest numbers 23

laser pointer project 512520

developing code 515517

further development and cleanup 517520

setup and first code 512514

LawyerSkill trait 143

lazy_static crate 341, 366371, 456

overview 366368

lazy_static! macro 367, 456

len_utf() method 418

.len() method 12

lenient language spouse 3

let else 103

let keyword 20, 25

lib.rs file 288

libraries 450

Library struct 158

LifetimeParam 324

lifetimes 189, 324

&str 189

annotations 190199

in functions 191

in types 192195

anonymous lifetime 195199

interior mutability 199208

line! macro 454, 473

LocalKey type 458

.lock() method 398

Logger struct 367, 369

loops 6670

low level 70

M

macros 437, 461

keeping code clean with 475479

reading from standard library 470475

reasons for 462

standard library 451460

cfg! macro 458460

column! macro 454

file! macro 454

line! macro 454

macro_rules! macro 463

matches! macro 474

module_path! macro 454

thread_local! macro 456458

unreachable! macro 452454

todo! macro 212214

writing 463470

main.rs file 288

main() function 16, 514

main() method 369

.make_book() function 214

make_fear_closure() function 247

.map_while() method 182

.map() method 156, 170, 174, 414415

mapping 170173

mapping arrays 414

match guard 63

match keyword 52, 101

match statements 6165

.match_indices() method 183

math() function 294296

::MAX 23

.max() method 424

maximum length 49

MedicalSkill trait 143

mem module 12, 437

mem::drop() function 438

mem::take() function 446447

memory 2830

const and static 33

Copy types 4245

std::mem module 437442

strings 3033

memory allocation 34

.metadata() method 521

method chaining 152

method signatures 131135

methods 71, 81

closures inside 163164

ending in _unchecked 334

::MIN 23

.min_width() method 524

.min() method 424

minimum length 49

mod city module 286

mod country module 286

mod keyword 288, 293

mod province module 286

modules 283289

basics of 283

modules inside modules 286289

pub keyword 285

monomorphism 377

MonsterBehavior trait 138

move keyword 229231

move semantics 42

Mul trait 422

MulAssign trait 422

mut keyword 54

mut self 307

mutability 24

interior 199208

Cell 200

Mutex 204206

RefCell 201204

RwLock 207

static mut 331332

mutable references 3538, 50

only immutable references 37

only one mutable reference 37

problem situation 37

mutable statics 328

Mutex 204206, 250, 254

Mutex<String> 367

my_number as char problem 10

MyType type 92

N

Naive types 350

$name, ident identifier 469

Neg trait 422

newtypes 147149

NewUserRequest struct 343

.next() method 156157, 159, 265

num_bigint crate 420

num_to_parse String 296

numbers, smallest and largest 23

O

.ok_or_else() method 172173

.ok_or() method 172

.ok() method 170172, 175

OKAY_CHARACTERS const 295

once_cell crate 341, 366, 368371

lazy_static 366368

OnceCell 369371

OnceCell::new() method 369

open_file() function 458

open() method 389

OpenOptions 389392

OpenOptions struct 390

Operation enum 299

Option 90, 95105, 156, 174, 438

options() method 390

_or_else methods 172

.or_insert() method 110111

orphan rule 147149

OS threads 225

OsString 434

outer attribute 266

Output type 403

ownership 28

references to functions 3842

P

padding characters 49

Painter 516

panic 96

panic hooks 437, 442447

panic! macro 122126, 289, 442443

PanicInfo struct 443444

par_chars() method 355

par_into_iter() method 355

par_iter_mut() method 355

par_iter() method 355

Paragraph widget 493

parse_and_log_str() function 118

parse_int() function 120

.parse() method 104, 122, 172

PartialEq trait 422

PartialOrd trait 94, 422

.path() method 521

pattern matching 98

if let 102

let else 103

while let 104

Pattern trait 184

.payload() method 444

.peekable() method 184

Pin 402

pointer address 48

pointer_hover_pos() method 516

pointers 2930

poll() method 403, 496

polymorphic functions 377

.pop() method 159, 433, 522

popular crates

lazy_static and once_cell 366371

serde crate 342344

Pos2 struct 515

Position struct 133

.position() method 179

prelude section 211

prelude, standard library 450

pretty printing 22

primitive types 714

print_all_three_things() function 122

print_country() function 3940

print_item() function 92

print_names() method 85

print_number() function 43

print_things module 283

printing 1620, 22, 4651

println! macro 231, 471

prints_country() function 4344

process_city_values() function 84

programmers 4

Programming Rust 461

programs 4

prototyping 212

pub keyword 149, 285

.push_str() method 509

.push() method 56, 522

Q

qualifications, traits as 142

Quantity type 319

R

rand crate

rolling dice with 337339

using 336

rand keyword 374

RangeInclusive struct 515

ratatui crate 492, 501, 512

Rayon crate 341, 354357

Rc (reference counter) 219225, 250

avoiding lifetime annotations with 223225

using in practice 220223

why Rc exists 219

.read_line() method 380

read_to_string() method 389, 483

.read() method 390, 481

ReadDir 521

reading documentation 262271

[src] button 264

assert_eq! 262

attributes 265271

searching 264

traits 265

Rect struct 515

.recv() method 258259

ref mut i32 35

RefCell 201204

reference cycle 222

references 30, 34, 87

mutable references 3538

only immutable references 37

only one mutable reference 37

problem situation 37

to functions 3842

referencing 36

--release part 380

Rem trait 422

.render_widget() method 493

.replace() function 439

request_repaint() method 517

RequestBuilder struct 397

reqwest crate 366, 371, 397399, 401402, 406

reqwest::Client 366

Response struct 401

Result enum 90, 95105, 174

retain() method 434

return_item() function 91

.rev() method 178

RichText struct 522

.round() method 423

run_native() method 514

.run() method 131

Rust

backtraces 447450

basics of 1

files 388392

creating 388

opening existing 389

OpenOptions 389392

installing

accessing command-line arguments 382385

accessing environment variables 385387

on computer 373

through stdin 380382

working with user input 380387

overview of 26

unsafe Rust 329335

methods ending in _unchecked 334

overview of 329

transmute() function 332334

using static mut in 331332

rustc compiler 374

Rustonomicon, The 330

RwLock 207

S

SaysHello 362

scoped threads 253, 256

screen_rect() method 516, 524

searching 264

select! macro 408

self keyword 71

Self type 82

.send() method 257258

Sense enum 516

serde crate 341344, 488

serde_json crate 343, 488

serde_json::from_str() function 489

serde_yaml crate 343

Serialize attribute 342343

.serve() method 505

set_hook() method 443

set_var() method 291, 387

.set() method 369

shadowing 2527

short circuit 178

shrink_to_fit() method 433

size_of_val() function 31, 437

size_of() function 12, 437

skinny arrow 18

.skip_while() method 182

.skip() method 383

sleep() function 407

slices 55

smallest numbers 23

smurf 310

.sort_unstable() method 430

.sort() method 430

spawn() function 226227, 229, 231, 351

specialized definition 377

.split_at_mut() method 431

.split_at() method 431

src button 264

src/main.rs 122

stack 2830

standard library 412, 437

arrays 413417

destructuring and mapping 414

implementing Iterator 413

using from_fn() to make 415417

associated items and associated constants 424428

bool 428

char 417

floats 423

integers 419423

Add trait and other similar traits 420423

checked operations 419

macros 451460

cfg! macro 458460

column! macro 454

file! macro 454

line! macro 454

module_path! macro 454

thread_local! macro 456458

unreachable! macro 452454

panic hooks 442447

prelude 450

reading macros from 470475

String 432434

time crate 344349

tour of 437

.start() method 507

State type 512

static methods 81

static mut 331332

statics, mutable 328

status() method 449

std library 437

std::backtrace module 447

std::cell::OnceCell 370

std::cmp::max() function 424

std::cmp::min() function 424

std::env::args() method 382

std::env::set_var() function 292, 386

std::env::var() function 291

std::env::vars() function 385

std::ffi module 434

std::fs module 388389

std::fs::read_dir() function 521

std::fs::write() function 388

std::io module 382

std::io::Write trait 388

std::mem module 12, 437442

std::mem::size_of_val() function 78

std::ops::Add 129

std::panic module 442

std::sync::mpsc 256

std::sync::OnceLock 370

std::thread module 355

std::thread::sleep() function 348

std::thread::spawn() function 225

std::time module 344

Stdin struct 380

stdin() function 380

Stopwatch struct 496

Stream trait 410

strict Rust spouse 3

string slice 30

String type 30, 3233, 128, 148151, 342, 434

String::from_utf8() method 121122

String::new() method 507

String::with_capacity() method 432

strings 714, 3033

strong_count() method 221

structs 7283

implementing 8183

Sub trait 422

Sub<Instant> 345

SubAssign trait 422

Subtract variant 299

Subtractor struct 294

.sum() method 182

.swap() function 438439

SystemError enum 363

SystemTime struct 347

T

.take_damage() method 138139

take_fifth() function 99

.take_guess() method 509

take_hook() method 446

.take_while() method 182

take() function 438, 440441

.take() method 153, 160, 182

terminal stopwatch and clock 492502

developing code 495498

further development and cleanup 499

setup and first code 492494

test-driven development (TDD) 282, 293302

building calculator 294296

putting calculator together 296302

testing 282, 289293

and test-driven development 293302

crates 283

modules 283289

basics of 283

modules inside modules 286289

pub keyword 285

when tests fail 290292

writing multiple tests 292

TextEdit 524

.then_some() method 412, 429

.then() method 429

thiserror crate 341, 360362

thread_local! macro 456458

thread::scope() method 254

thread::spawn() method 351

threads 209, 225233

cloning on write 215219

move keyword 230

spawning 225227

type aliases 214

types of closures 229

waiting for to finish 227229

time crate 344349

time module 341

TimeOfDay enum 247

.to_digit() method 346

.to_string() method 134, 364

todo! macro 212214, 471

token parser 463

ToOwned trait 216

ToString trait 134135, 364

trait bounds 137, 327

Trait Implementations 4243

trait objects 242, 277

trait word 22

traits 128145

as bounds 140142

as qualifications 142

AsRef trait 149151

blanket trait implementations 362366

From trait 145147

information on 265

method signatures 131135

more complex examples 135140

orphan rule 147149

putting Box around 273276

transferring ownership 50

transmute() function 332335

.trim_end_matches() method 297

.trim_left_matches() method 297

.trim_right_matches() method 297

.trim_start_matches() method 297

.trim() method 381

.trunc() method 423

.truncate() method 390

try_join! macro 409

.try_lock() method 206

.try_recv() method 258

TryFrom trait 476, 478

tt (token tree) 468

TUI (text- or terminal-based user interface) 492

tui crate 492

tuples 5860

type aliases 214

type erasure 277

type inference 14

TypeParam 324

types 71

building 7188

destructuring 8387

dot operator 87

references 87

See also enums; structs

collection types 5360

arrays 5355

tuples 5860

vectors 5558

control flow 6070

basic 60

loops 6670

match statements 6165

Copy types 4245

inference 14

lifetime annotations in 192195

more complex 52

traits 128145

using multiple 79

typing tutor 481487

developing code 482484

further development and cleanup 484

ideas for further development 486

setup and first code 481

U

Ui struct 513

unfinished projects 480, 503

directory and file navigator 520527

developing code 522524

further development and cleanup 524526

setup and first code 521

setup for 481

terminal stopwatch and clock 492502

developing code 495498

further development and cleanup 499

setup and first code 492494

Wikipedia article summary searcher 487492

developing code 488

further development and cleanup 490

setup and first code 487

word-guessing game 504512

developing code 506509

further development and cleanup 509512

setup and first code 504506

unit type 58

UNIX_EPOCH const 347

unreachable! macro 452454

unsafe keyword 329330

unsafe Rust 323, 329335

methods ending in _unchecked 334

overview of 329

transmute() function 332334

using static mut in 331332

unwrap method 122126

.unwrap_err() method 361

.unwrap_or_default() method 306

.unwrap_or_else() method 163, 172

.unwrap_or() method 163, 172

.unwrap() method 97, 257, 289, 435, 485, 490, 523

.update() method 265, 513, 517

ureq crate 487

use keyword 7778

use of moved value 39

use statement 252, 451

user input 380387

accessing command-line arguments 382385

accessing environment variables 385387

through stdin 380382

UserName(String type) 342

usize type 7

UTF-8 31

V

values, variables without 45

var() method 387

variable names 49

variant 75

Vars 385

Vec type 5556, 147, 227, 412, 430432

Vec::new() method 507

Vec::with_capacity() method 57

vec! macro 56

Vec2 struct 515

VecDeque 117

vectors 5558

W

web servers

word-guessing game 504512

developing code 506509

further development and cleanup 509512

setup and first code 504506

where keyword 94

while let 104

_while methods 182

Wikipedia article summary searcher 487492

developing code 488

further development and cleanup 490

setup and first code 487

.windows() method 183

.with_state() method 509, 512

.with() method 456

word-guessing game 504512

developing code 506509

further development and cleanup 509512

setup and first code 504506

.write_all() method 388

write_fmt() method 471

write! macro 133, 390, 470

.write() method 390

Y

ymd (year month day) 350

Z

zero-cost abstractions 166

.zip() method 166, 180

zipping 180185