Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
Generic Types, Traits, and Lifetimes Every programming language has tools for effectively handling the duplication of concepts. In Rust, one such tool is generics: abstract stand-ins for concrete types or other properties. We can express th...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~4 min read
Generic Data Types We use generics to create definitions for items like function signatures or structs, which we can then use with many different concrete data types. Let’s first look at how to define functions, structs, enums, and methods...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~10 min read
Defining Shared Behavior with Traits A trait defines the functionality a particular type has and can share with other types. We can use traits to define shared behavior in an abstract way. We can use trait bounds to specify that a generic t...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~12 min read
Validating References with Lifetimes Lifetimes are another kind of generic that we’ve already been using. Rather than ensuring that a type has the behavior we want, lifetimes ensure that references are valid as long as we need them to be. O...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~21 min read
Writing Automated Tests In his 1972 essay “The Humble Programmer,” Edsger W. Dijkstra said that “program testing can be a very effective way to show the presence of bugs, but it is hopelessly inadequate for showing their absence.” That does...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~1 min read
How to Write Tests Tests are Rust functions that verify that the non-test code is functioning in the expected manner. The bodies of test functions typically perform these three actions: • Set up any needed data or state. • Run the code you...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~15 min read
Controlling How Tests Are Run Just as cargo run compiles your code and then runs the resultant binary, cargo test compiles your code in test mode and runs the resultant test binary. The default behavior of the binary produced by cargo test...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~5 min read
Test Organization As mentioned at the start of the chapter, testing is a complex discipline, and different people use different terminology and organization. The Rust community thinks about tests in terms of two main categories: unit tests...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~8 min read
An I/O Project: Building a Command Line Program This chapter is a recap of the many skills you’ve learned so far and an exploration of a few more standard library features. We’ll build a command line tool that interacts with file and comman...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~1 min read
Accepting Command Line Arguments Let’s create a new project with, as always, cargo new. We’ll call our project minigrep to distinguish it from the grep tool that you might already have on your system: $ cargo new minigrep Created binary (ap...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~4 min read
Reading a File Now we’ll add functionality to read the file specified in the file_path argument. First, we need a sample file to test it with: We’ll use a file with a small amount of text over multiple lines with some repeated words. Listin...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~1 min read
Refactoring to Improve Modularity and Error Handling To improve our program, we’ll fix four problems that have to do with the program’s structure and how it’s handling potential errors. First, our main function now performs two tasks: It pa...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~17 min read
Adding Functionality with Test-Driven Development Now that we have the search logic in src/lib.rs separate from the main function, it’s much easier to write tests for the core functionality of our code. We can call functions directly with v...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~6 min read
Working with Environment Variables We’ll improve the minigrep binary by adding an extra feature: an option for case-insensitive searching that the user can turn on via an environment variable. We could make this feature a command line optio...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~6 min read
Redirecting Errors to Standard Error At the moment, we’re writing all of our output to the terminal using the println! macro. In most terminals, there are two kinds of output: standard output (stdout) for general information and standard er...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~3 min read
Functional Language Features: Iterators and Closures Rust’s design has taken inspiration from many existing languages and techniques, and one significant influence is functional programming. Programming in a functional style often includes...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~1 min read
Closures Rust’s closures are anonymous functions you can save in a variable or pass as arguments to other functions. You can create the closure in one place and then call the closure elsewhere to evaluate it in a different context. Unlike f...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~14 min read
Processing a Series of Items with Iterators The iterator pattern allows you to perform some task on a sequence of items in turn. An iterator is responsible for the logic of iterating over each item and determining when the sequence has fini...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~6 min read
Improving Our I/O Project With this new knowledge about iterators, we can improve the I/O project in Chapter 12 by using iterators to make places in the code clearer and more concise. Let’s look at how iterators can improve our implementati...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~5 min read
Performance in Loops vs. Iterators To determine whether to use loops or iterators, you need to know which implementation is faster: the version of the search function with an explicit for loop or the version with iterators. We ran a benchma...
doc.rust-lang.org The Rust Programming Language Book 2024-02-01 ~2 min read
"Sometimes bad designs will fail faster in Rust"

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, and research. These operators give you finer control — click an example to try it.

Find pages containing all your words. Pages where the words appear together rank higher.
Quote part of your query to keep those words together as an exact phrase within a larger search.
Wrap the whole query in quotes for a verbatim search that matches text exactly, punctuation and all — perfect for Rust syntax. Needs at least 3 characters.
Limit results to a single site. Works on its own () too. One site: per search.

Use the tabs and filters above the results to narrow by content type, publication year, and sort order.