Start free trial
Trending New Genres Authors
EnglishEnglish
EspañolSpanish
简体中文Chinese
繁體中文Chinese (Traditional)
FrançaisFrench
DeutschGerman
日本語Japanese
PortuguêsPortuguese
ItalianoItalian
한국어Korean
РусскийRussian
NederlandsDutch
العربيةArabic
PolskiPolish
हिन्दीHindi
Tiếng ViệtVietnamese
SvenskaSwedish
ΕλληνικάGreek
TürkçeTurkish
ไทยThai
ČeštinaCzech
RomânăRomanian
MagyarHungarian
УкраїнськаUkrainian
IndonesiaIndonesian
DanskDanish
SuomiFinnish
БългарскиBulgarian
עבריתHebrew
NorskNorwegian
HrvatskiCroatian
CatalàCatalan
SlovenčinaSlovak
LietuviųLithuanian
SlovenščinaSlovenian
СрпскиSerbian
EestiEstonian
LatviešuLatvian
فارسیPersian
മലയാളംMalayalam
தமிழ்Tamil
اردوUrdu
Searching...
SoBrief
Rust In Practice

Rust In Practice

A Programmers Guide to Build Rust Programs, Test Applications and Create Cargo Packages
Build Rust programs that compile safely, test reliably, and grow from command line to shared data.
by Rustacean Team 2023 174 pages
Listen
Immersive
V2.3
Amazon Kindle Audible
Try Full Access for 3 Days
Unlock listening & more!
Continue

Key Takeaways

Choose Rust when performance and memory safety matter more than instant flexibility.

A deliberate tradeoff. Rust is presented as a compiled, statically typed language for programs that need close control over performance, memory, or concurrency. Its ownership rules aim to prevent common memory errors before a program runs. The book contrasts this with Python, which it describes as a fit for readable scripting and rapid prototyping, and with C++ and Go, which make different tradeoffs around control, memory management, and concurrency.

Let the project decide. Rust is not framed as universally superior. A small script may benefit more from quick development than from low-level control, while systems software may justify Rust's stricter rules. The book's opening Hello World and calculator examples make the practical point: learn the language by building, not just by comparing feature lists.

Analysis

What's useful here is the focus on costs rather than language rivalries. A language shapes the kinds of mistakes that are easy to make, the kinds of abstractions available, and the pace of development. Rust's safety guarantees are valuable when memory errors or concurrency bugs carry serious consequences, but its compile-time constraints can slow early experimentation. The right comparison is therefore not simply speed versus readability. It is the full cost of building, maintaining, and operating a particular program.

Treat ownership as a compile-time map of who may use each value.

One owner, clear lifetime. In Rust, each value has an owner. When that owner leaves scope, the value is dropped, which lets the language manage memory without requiring the programmer to manually free every value. Ownership is not simply a rule about whether data lives on the stack or heap. It is a rule about responsibility for a value and how long that value remains valid.

Borrow without taking over. A reference lets code use a value without becoming its owner. Rust permits multiple shared references at once, or one mutable reference at a time. For example, a function can receive a mutable reference to a number, increment it, and return while the caller still owns the number. The compiler checks these access rules before execution.

Analysis

Ownership makes a hidden software question visible: who is responsible for this data, and when does that responsibility end? That clarity can make code easier to audit, especially when values pass through several functions. The tradeoff is that programmers must learn to think about lifetimes and borrowing as part of ordinary design, not as a cleanup task. This model is strongest when the rules explain the program's real data flow. If they feel obstructive, the useful response is often to reconsider the data structure or ownership boundary.

Keep bindings immutable by default, and use mutability only for genuine updates.

Changes require permission. A Rust binding created with `let` cannot be reassigned unless it is declared with `mut`. This makes accidental changes harder to introduce. A counter that increases inside a loop is a natural use for mutability; a value that is calculated once and then read can remain immutable.

Shadowing is a new binding. Rust also allows a later `let` statement to reuse a name. This is called shadowing. It creates a new binding that hides the earlier one, rather than changing that earlier binding in place. Shadowing can be useful when transforming a value, including changing its type, while keeping the transformation readable. Constants are different: they require an explicit type and a value known at compile time.

Analysis

This distinction gives Rust two different ways to express change. Mutability says that one binding may be updated; shadowing says that a new binding replaces the old name in the current view of the code. That can make transformations easier to read without suggesting that a value is being modified in place. The design also encourages a useful review question: does this variable need to change, or is each step better represented as a new value? Not every binding benefits from staying immutable, but the default makes updates conspicuous.

Model domain records with structs, then use traits to share behavior.

Give related data a shape. A struct combines named fields into a type that represents something meaningful in a program. The book's `Student` example groups an identifier, name, major, and year. A `Rectangle` can hold width and height, with an associated method to calculate its area. Named fields make the purpose of each piece of data easier to see than a loose collection of values.

Share behavior through traits. A trait describes behavior that different types can implement. For example, a `HasArea` trait can require an `area` method, and a generic function can accept any type that implements it. Rust does not use struct inheritance in the way some languages do. Composition, where one struct contains another, and traits provide ways to reuse data and behavior.

Analysis

Structs and traits separate two questions that are often tangled together: what information does this value hold, and what operations can it perform? That separation supports clearer interfaces and makes generic code possible without requiring every type to share one parent class. The book's rectangle example is intentionally small, but the design principle scales to larger systems. A useful caution is to create a trait for a meaningful shared capability, not merely to wrap one method in extra ceremony.

Represent finite choices with enums, then let match make cases explicit.

Make states concrete. An enum defines a type with a limited set of variants. A card suit, for example, can be represented by four named variants rather than by arbitrary strings or numbers. Variants can also carry data, such as a card variant that includes its suit.

Handle each case. A `match` expression compares a value with patterns and runs the code for the matching case. It can also extract data from a variant, such as binding the suit inside a card value. Rust checks that a match covers the possible cases. A wildcard pattern can handle remaining cases, but explicit arms often make the program's decisions easier to inspect. The book also shows guards, which add conditions to a pattern.

Analysis

Enums do more than make values readable. They constrain a program's state space: a function that receives a suit cannot silently receive an unrelated string. Matching then turns decisions into visible structure, which helps a reader see what happens for each state. This is especially useful when a program grows and new cases are added. A wildcard arm is convenient, but can conceal the fact that an additional variant deserves its own behavior, so explicit handling is often preferable when completeness matters.

Let Cargo turn source files into a build, test, and release workflow.

One tool, many tasks. Cargo is Rust's project and package manager. `cargo new` creates a project, while `cargo build` compiles it and `cargo run` builds and runs it. `cargo check` provides a quick compilation check, `cargo test` runs tests, and `cargo doc` generates documentation. Release builds use an optimization option, and Cargo can package and publish a crate.

Know the project pieces. A crate is a compiled unit of Rust code, either an executable or a library. A package groups crates and project metadata, including dependencies, in `Cargo.toml`. Adding a library as a project dependency lets Cargo download and build it as part of the project. The book also introduces modules and paths, which organize code and identify where items live.

Analysis

Cargo matters because it makes project work repeatable. The manifest records dependencies and metadata, while familiar commands turn building, testing, and documentation into a routine rather than a collection of manual steps. That is more than convenience: shared commands reduce ambiguity between developers and environments. Beginners should keep one distinction clear, though: adding a library dependency to a project is different from installing a standalone command-line tool. The book surveys many Cargo commands, but the everyday build, run, check, and test cycle is the core.

Use Rust's standard library for collections, errors, files, and synchronization.

Start with built-in tools. Rust's standard library includes collections such as vectors and hash maps, file and input-output operations, string utilities, networking, time, and synchronization primitives. A `Result` value represents either success or an error; the `?` operator can pass an error back to the caller. These tools cover common needs without requiring a separate crate for every task.

Reach beyond the basics carefully. The book demonstrates a small TCP server, reading a file, sharing a counter across threads with `Arc` and `Mutex`, and using macros such as `println!`. Macros generate code during compilation and can make repeated patterns concise. The file-sorting command-line example adds the external `walkdir` crate to traverse directories and sorts files by modification time.

Analysis

A standard library is a set of shared building blocks, but it also teaches a language's preferred way to express common work. Learning Result, collections, and file operations gives a beginner reusable patterns before introducing a large dependency stack. The examples also reveal that convenience has limits: a short server or file utility is a learning exercise, not necessarily a complete production design. Reading errors and checking failure cases should be part of adapting these examples, rather than treating successful output as proof of robustness.

Test the behavior users see, not only the functions you wrote.

Check small units first. Unit tests exercise individual functions or components, often with known inputs and expected outputs. Rust tests are marked with `#[test]` and can use assertions such as `assert eq!`. Cargo runs them with `cargo test`, making tests part of the ordinary development workflow.

Check the whole path too. The book's file-sorting CLI offers a concrete test target: provide a directory, run the sorting logic, and compare the resulting paths with an expected sequence. An integration test can launch the executable as a separate process and inspect its output. These approaches catch different problems. A function test can isolate sorting behavior, while a process-level test can reveal failures in argument handling or output formatting.

Analysis

Testing at multiple levels mirrors the way confidence is built in other engineered systems: verify components, then verify that the components work together in the setting that matters. For a command-line tool, correct internal sorting is not enough if the program misreads its arguments or prints an unusable result. Tests are only as good as their assumptions, however. A test that relies on fixed file modification times or a particular environment can become brittle, so fixtures and expected outputs need deliberate design.

Choose an ownership tool. `Box<T>` owns a value stored on the heap. `Rc<T>` allows shared ownership within a single thread, while `Arc<T>` provides reference counting that can be shared across threads. The examples use `Arc` with a mutex when multiple threads need to update shared data safely. These types solve different ownership problems, so they are not interchangeable conveniences.

Watch for circular links. Reference counting cannot reclaim values whose strong references keep one another alive. A parent and child that each strongly reference the other can form a reference cycle. `Weak<T>` provides a non-owning reference that does not increase the strong reference count. Using a weak link, often for a relationship such as a child's pointer to its parent, can prevent the cycle from keeping otherwise unused values alive.

Analysis

Smart pointers make ownership relationships explicit in the data structure itself. A single owner, shared local ownership, and shared cross-thread access are different requirements, and choosing the right pointer clarifies the intended topology. Reference cycles show an important limit: automatic reclamation works only when ownership links eventually let go. Weak references are a targeted remedy, but they add the possibility that upgrading a reference fails because the value is gone. That possibility should be handled as part of the program's logic.

Analysis

Rust In Practice is a beginner-oriented programming handbook, organized as a guided survey rather than a sustained project narrative. It moves from installation and basic syntax through ownership, data modeling, Cargo, the standard library, a command-line application, testing, and smart pointers. Its strongest teaching idea is that Rust's safety model is not an isolated feature: ownership, borrowing, types, and explicit error handling shape everyday programming decisions.

The most useful way to read the book is as a map of topics to practice. The calculator, student record, file sorter, and shared counter give concrete footholds, while Cargo commands provide a path from a source file to a runnable and testable project. The examples also make abstract distinctions visible, such as a struct versus an enum, or shared references versus a mutable one.

The material is uneven as a technical reference. Some explanations simplify language behavior, and several snippets are incomplete, inconsistent, or unsuitable as copy-and-run programs. The book's stated ambitions include asynchronous programming and generics, but the supplied text gives those subjects little practical treatment. Installation and editor instructions are also more prescriptive than the core ideas require. Readers should therefore use the book to orient themselves, then validate code and current tooling against Rust's official documentation and compiler output.

Its deeper value is not a catalog of commands. It is the habit of asking who owns a value, what states a type can represent, how errors travel, and how a program will be tested. Those questions make Rust's restrictions intelligible. The language can feel demanding at first, but the discipline pays off when code must remain predictable as its data structures, dependencies, and concurrency grow.

Summary in 30 Seconds
Rust checks ownership and borrowing rules before a program runs, helping prevent common memory errors without manual freeing. Structs group related data, enums represent defined alternatives, and match expressions require cases to be handled. Cargo manages builds, dependencies, tests, and releases. Unit tests check components, while integration tests can run a program and inspect its output. Box, Rc, Arc, and Weak support distinct ownership and sharing needs.
Contains spoilers

Last updated:

Report Issue
Want to read the full book?

Glossary

Ownership

Responsibility for a value

Rust's ownership system assigns each value an owner, and the value is dropped when that owner leaves scope. Ownership gives the compiler information about when data remains valid and when it can be released. It is a central part of Rust's memory-safety model and does not require programmers to manually free ordinary values.

Borrowing

Using data through references

Borrowing lets code access a value through a reference without taking ownership of it. Rust checks borrowing rules at compile time: code may hold multiple shared references at once, or one mutable reference, but not both kinds of access simultaneously. These rules help prevent invalid access and unsafe interference between uses of data.

Trait

A shared behavior contract

A trait describes behavior that a type can implement, typically through required methods and associated types. Generic functions can use trait bounds to accept different types that provide the required behavior. Traits support abstraction and code reuse without requiring struct inheritance, and they can also be used with dynamic dispatch in appropriate contexts.

Pattern matching

Selecting behavior by structure

Pattern matching compares a value with patterns and runs the branch that fits. In Rust, match can handle enum variants, inspect ranges, apply guards, and extract data from nested values. The compiler checks that match expressions account for the possible cases, helping make decisions over structured data explicit.

Cargo

Rust project manager

Cargo is Rust's package manager and project tool. It reads project metadata and dependencies from Cargo.toml, builds projects, runs tests, generates documentation, and supports packaging and publishing. Commands such as cargo new, cargo run, and cargo test provide a repeatable workflow for developing Rust applications and libraries.

Crate

A compiled Rust unit

A crate is a unit of Rust code compiled together. A binary crate produces an executable and has a program entry point, while a library crate provides code that other crates can use. Crates help organize code into reusable pieces and can depend on other crates managed through Cargo.

Package

A Cargo-managed project

A package is a collection of one or more crates managed as a single project. Its Cargo.toml manifest records information such as the package name, version, and dependencies. A package may include a library crate, one or more binary crates, or both, and Cargo uses its metadata to build and distribute the project.

Smart pointer

Pointer with ownership behavior

A smart pointer is a type that points to data while providing additional ownership or memory-management behavior. Rust's examples include Box<T> for heap-owned data, Rc<T> for shared reference-counted ownership in one thread, and Arc<T> for reference-counted sharing across threads. Each supports a different data-sharing requirement.

Weak<T>

Non-owning counted reference

Weak<T> is a non-owning reference associated with reference-counted data such as Rc<T>. Unlike a strong reference, it does not keep the value alive by increasing the strong reference count. It is useful for links that should not own their target, such as a parent pointer, and can help prevent reference cycles.

Download PDF

To save this Rust In Practice summary for later, download the free PDF. You can print it out, or read offline at your convenience.
Download PDF
File size: 0.31 MB     Pages: 16

Download EPUB

To read this Rust In Practice summary on your e-reader device or app, download the free EPUB. The .epub digital book format is ideal for reading ebooks on phones, tablets, and e-readers.
Download EPUB
File size: 1.36 MB     Pages: 17
Want to read the full book?
Follow
Listen
Home
Swipe
Library
Get App
Try Full Access for 3 Days
Listen, bookmark, and more
Compare Features Free Pro
📖 Read Summaries
Read unlimited summaries. Free users get 3 per month
🎧 Listen to Summaries
Listen to unlimited summaries in 40 languages
—
❤️ Unlimited Bookmarks
Free users are limited to 4
—
📜 Unlimited History
Free users are limited to 4
—
📥 Unlimited Downloads
Free users are limited to 1
—
Risk-Free Timeline
Today: Get Instant Access
Listen to full summaries of 26,000+ books. That's 12,000+ hours of audio!
Day 2: Trial Reminder
We'll send you a notification that your trial is ending soon.
Day 3: Your subscription begins
You'll be charged on Nov 24,
cancel anytime before.
Consume 2.8× More Books
2.8× more books Listening Reading
Our users love us
600,000+ readers
Trustpilot Rating
TrustPilot
4.6 Excellent
This site is a total game-changer. I've been flying through book summaries like never before. Highly, highly recommend.
— Dave G
Worth my money and time, and really well made. I've never seen this quality of summaries on other websites. Very helpful!
— Em
Highly recommended!! Fantastic service. Perfect for those that want a little more than a teaser but not all the intricate details of a full audio book.
— Greg M
Save 62%
Yearly
$119.88 $44.99/year/yr
$3.75/mo
Monthly
$9.99/mo
Start a 3-Day Free Trial
3 days free, then $44.99/year. Cancel anytime.
Unlock a world of fiction & nonfiction books
26,000+ books for the price of 2 books
Read any book in 10 minutes
Discover new books like Tinder
Request any book if it's not summarized
Read more books than anyone you know
#1 app for book lovers
Lifelike & immersive summaries
30-day money-back guarantee
Download summaries in EPUBs or PDFs
Cancel anytime in a few clicks

Why one summary?

Scanner
Find a barcode to scan

⭐
⭐
⭐
We have a special gift for you
Open
38% off
DISCOUNT FOR YOU
⭐
⭐
⭐
$79.99
$49.99/year
Only $4.16 per month
Continue
2 taps to start, super easy to cancel
Settings
General
Widget
Loading...