Open-source project
rust-lang-nursery/rust-cookbook avatar
rust-lang-nursery/rust-cookbook

Rust Cookbook: tested Rust examples you can copy into a cargo project

https://rust-lang-nursery.github.io/rust-cookbook

2,619 stars330 forksRustCC0-1.0

At a glance

What is it?
The Rust Cookbook is a collection of short, tested Rust examples covering common tasks across the ecosystem. It is a reference to copy from, not a book to read cover to cover, and the repository ships a workspace of runnable crates behind the prose.
Who is it for?
Adopt the Rust Cookbook if you already write Rust and want tested snippets for a specific task, and clone it locally when you need the examples offline. Do not adopt it as a first Rust course or as a sequential tutorial; it has no narrative and no release cycle, so there is no version to pin beyond the workspace version 1.1.0.
Can I use it commercially?
Yes. CC0-1.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 38 days ago.
What is it written in?
Mainly Rust, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 24, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What the Rust Cookbook is for, and who should open it

The README describes the project as "a collection of simple Rust examples that demonstrate good practices to accomplish common programming tasks, using the crates of the Rust ecosystem." That sentence sets the boundary. It is a lookup table for people who already know the language and need a working pattern for one narrow job: hashing a file, walking a directory, parsing JSON, spawning a thread pool. Each entry is meant to be lifted whole.

The README makes a stronger claim than most snippet collections: the examples are "complete, and suitable for copying directly into new cargo projects" and are "tested and guaranteed to work." That guarantee is the product. Plenty of blog posts show a Rust snippet that compiled in 2019. The Cookbook's value is that its examples live in the repository as code that the project's own test run exercises, so a stale API is a build failure rather than a silent trap for the reader.

The audience is narrow on purpose. If you are still learning ownership and borrowing, the examples assume you can read them without a chapter of explanation. The contributing guide says the project "is intended to be easy for new Rust programmers to contribute to," which is about who can add an example, not about who can learn the language from it.

How the examples are organized: a book over a cargo workspace

The repository is two things stacked. The prose you read in the browser is an mdBook, configured by book.toml, and the code behind it is a cargo workspace. The workspace members list in Cargo.toml groups crates by subject: algorithms, compression, concurrency, configuration, development tools, file, multimedia, parsing, safety critical, wasm, and web. That is the taxonomy you navigate in the rendered book.

Not every directory is a member. The exclude list in Cargo.toml holds back crates/database/sea_orm, crates/database/sqlx, crates/multimedia/playback, crates/web_leptos, crates/web_leptos_hydrate, crates/wasm_component_guest, and crates/wasm_component_host. Those examples exist in the tree but sit outside the default workspace build, presumably because they pull heavy or platform-specific dependencies. If you copy an example from one of those sections, you are on your own for the build.

The workspace sets edition 2024 and version 1.1.0 for its members, while the top-level rust-cookbook package still declares edition 2018. Since the package is marked publish = false, this is a documentation artifact rather than something you would depend on from crates.io. The workspace also carries a note that its dependencies are shared with the Rust Playground, warning that removing or changing them affects play.rust-lang.org. The examples are tuned to run in that environment, which is a useful hint about how self-contained each one is meant to be.

Installing the Rust Cookbook locally and running the first example

The README gives the offline path directly: clone the repository, install mdbook, and serve the book. Note that the README pins mdbook to version 0.4.43 while the Makefile installs 0.5.3 for its own targets. Use one or the other consistently, because the two versions are not the same tool.

bash
$ git clone https://github.com/rust-lang-nursery/rust-cookbook
$ cd rust-cookbook
$ cargo install mdbook --vers "0.4.43"
$ mdbook serve --open

After mdbook serve finishes, a browser tab opens on the local book and the terminal reports the address it is serving on. The README also notes that the built output lands in the book subdirectory, so you can skip the server and open the file directly.

bash
$ xdg-open ./book/index.html # linux
$ start .\book\index.html   # windows
$ open ./book/index.html    # mac

The second path is the one most readers actually want: you are not reading the book, you are checking that the example you copied compiles. The Makefile wraps the build and test cycle, and its help target lists every command it defines. Running make build installs mdbook first, builds the book, and copies assets into the output; make test runs cargo test and then ci/spellcheck.sh list. Running make dev chains the two, which is the fastest way to confirm that the example you just edited still passes.

The limits: no narrative, no release cadence, and examples outside the build

The Cookbook is the wrong tool for learning Rust from zero. There is no progression, no explanation of why one approach beats another, and no exercises. The README points new contributors at CONTRIBUTING.md, but nothing in the repository is structured as a course. If you need a guided path, this is not it.

The second limit is versioning. The repository has no releases, so there is no tag to pin, no changelog to read, and no way to say "I used Cookbook 1.1.0" in the sense a library user means it. The workspace version field is 1.1.0, but the package is publish = false and the project is documentation. You track master or you track nothing.

The third limit is the exclude list. Examples under the excluded directories are in the repository but outside the workspace members, so the project's own cargo test does not build them. The README's guarantee that examples are tested covers what the test run actually compiles. An example in an excluded crate is not covered by that sentence, and the repository does not document why each one was excluded.

Finally, the project is a nursery repository with no release artifacts. There is no packaged book to download from the project itself, so any PDF or offline copy you find circulating was produced by someone else, not published here.

Where the Cookbook sits next to Rust by Example and Rustlings

Rust by Example takes a different route to the same reader. It walks the language feature by feature, with runnable snippets embedded in a narrative order, so you move from hello world through generics to macros in a sequence the authors chose. The Cookbook has no sequence. Its unit is the task, and its index is the problem you are trying to solve, not a concept you are trying to learn. If you want to understand traits, read Rust by Example. If you already understand traits and need to parse a CSV file, open the Cookbook.

Rustlings differs again. It is a set of exercises with deliberate gaps that you fill in, and the feedback loop is a failing test you make pass. That is practice. The Cookbook gives you finished code and asks you to copy it. Neither replaces the other: Rustlings builds fluency, the Cookbook saves you from writing boilerplate you have written before.

The closest comparison inside the ecosystem is the standard library documentation's own examples, which are also tested. The difference is coverage. The Cookbook's stated scope is "the crates of the Rust ecosystem," so it reaches into serde, rand, tracing, and the rest of the dependency graph in a way the standard library docs cannot. That breadth is the reason the workspace has so many members and so many excluded ones.

Maintenance, licensing, and what a fork costs you

The repository is not archived, and the last push was on 2026-08-24. That is recent enough that stale examples are being fixed rather than left to rot, but there is no release history to inspect, so the only signal about activity is the commit stream itself.

The licence situation is unusually permissive and worth stating plainly. The README says Rust Cookbook is licensed under Creative Commons Zero v1.0 Universal, and that any contribution intentionally submitted for inclusion is dedicated to the public domain under the same terms. CC0 is a public domain dedication, not a copyleft licence. Copying an example into your own project, commercial or not, carries no attribution requirement under that licence.

The distinction that matters: the licence covers the Cookbook's text and examples, not the crates the examples call. Each of those carries its own licence, and the workspace's own dependency declarations are not a statement about the licences of the crates you end up adding to your Cargo.toml. If you fork the repository to run your own internal cookbook, the CC0 terms let you do that without asking, and the mdBook plus workspace layout means your fork is buildable with the same make build and make test targets. The maintenance burden you inherit is the one the project already carries: keeping examples compiling as the ecosystem's crates publish breaking changes.

Editorial conclusion

Adopt the Rust Cookbook if you already write Rust and want tested snippets for a specific task, and clone it locally when you need the examples offline. Do not adopt it as a first Rust course or as a sequential tutorial; it has no narrative and no release cycle, so there is no version to pin beyond the workspace version 1.1.0. Verify first that the example you copy compiles against your own dependency versions, since the workspace declares edition 2024 for its member crates while the top-level package still declares edition 2018, and the README's mdbook pin of 0.4.43 disagrees with the Makefile's 0.5.3.

Frequently asked questions

What is the Rust Cookbook?

It is a collection of short Rust examples for common programming tasks, built with the crates of the Rust ecosystem. The README says the examples are complete, suitable for copying into new cargo projects, and tested.

How do I read the Rust Cookbook offline?

Clone the repository, install mdbook with the version the README pins, and run mdbook serve. The built output also lands in the book subdirectory, which you can open directly in a browser.

Is the Rust Cookbook a good first book for learning Rust?

No. It is a task-indexed reference with no narrative progression, so it assumes you already read Rust. The README frames it as a way to accomplish common programming tasks, not as a course.

Are all the examples in the Rust Cookbook tested?

The README states the examples are tested and guaranteed to work, and the Makefile's test target runs cargo test. However, several crates are listed in the workspace exclude list, so they sit outside the default workspace build.

What licence does the Rust Cookbook use?

Creative Commons Zero v1.0 Universal. The README states that contributions intentionally submitted for inclusion are dedicated to the public domain under the same licence.

Official sources

  1. Issues
  2. License: CC0-1.0
  3. README
  4. rust-lang-nursery/rust-cookbook on GitHub
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/rust-lang-nursery-rust-cookbook.svg)](https://hysenlabs.com/projects/rust-lang-nursery-rust-cookbook)