Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
Lifetimes Rust enforces these rules through lifetimes. Lifetimes are named regions of code that a reference must be valid for. Those regions may be fairly complex, as they correspond to paths of execution in the program. There may even be h...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~8 min read
Limits of Lifetimes Given the following code: #[derive(Debug)] struct Foo; impl Foo { fn mutate_and_share(&mut self) -> &Self { &*self } fn share(&self) {} } fn main() { let mut foo = Foo; let loan = foo.mutate_and_share(); foo.share(); pri...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
Lifetime Elision In order to make common patterns more ergonomic, Rust allows lifetimes to be elided in function signatures. A lifetime position is anywhere you can write a lifetime in a type: &'a T &'a mut T T<'a> Lifetime positions can ap...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Unbounded Lifetimes Unsafe code can often end up producing references or lifetimes out of thin air. Such lifetimes come into the world as unbounded. The most common source of this is taking a reference to a dereferenced raw pointer, which p...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Higher-Rank Trait Bounds (HRTBs) Rust's Fn traits are a little bit magic. For instance, we can write the following code: struct Closure<F> { data: (u8, u16), func: F, } impl<F> Closure<F> where F: Fn(&(u8, u16)) -> &u8, { fn call(&self) ->...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Subtyping and Variance Rust uses lifetimes to track the relationships between borrows and ownership. However, a naive implementation of lifetimes would be either too restrictive, or permit undefined behavior. In order to allow flexible usag...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~10 min read
Drop Check We have seen how lifetimes provide us some fairly simple rules for ensuring that we never read dangling references. However up to this point we have only ever interacted with the outlives relationship in an inclusive manner. That...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~8 min read
PhantomData When working with unsafe code, we can often end up in a situation where types or lifetimes are logically associated with a struct, but not actually part of a field. This most commonly occurs with lifetimes. For instance, the Ite...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~7 min read
Splitting Borrows The mutual exclusion property of mutable references can be very limiting when working with a composite structure. The borrow checker (a.k.a. borrowck) understands some basic stuff, but will fall over pretty easily. It does...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~5 min read
Type Conversions At the end of the day, everything is just a pile of bits somewhere, and type systems are just there to help us use those bits right. There are two common problems with typing bits: needing to reinterpret those exact bits as...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Coercions Types can implicitly be coerced to change in certain contexts. These changes are generally just weakening of types, largely focused around pointers and lifetimes. They mostly exist to make Rust "just work" in more cases, and are l...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
The Dot Operator The dot operator will perform a lot of magic to convert types. It will perform auto-referencing, auto-dereferencing, and coercion until types match. The detailed mechanics of method lookup are defined here, but here is a br...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~3 min read
Casts Casts are a superset of coercions: every coercion can be explicitly invoked via a cast. However some conversions require a cast. While coercions are pervasive and largely harmless, these "true casts" are rare and potentially dangerous...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Transmutes Get out of our way type system! We're going to reinterpret these bits or die trying! Even though this book is all about doing things that are unsafe, I really can't emphasize enough that you should deeply think about finding Anot...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
Working With Uninitialized Memory All runtime-allocated memory in a Rust program begins its life as uninitialized. In this state the value of the memory is an indeterminate pile of bits that may or may not even reflect a valid state for the...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Checked Uninitialized Memory Like C, all stack variables in Rust are uninitialized until a value is explicitly assigned to them. Unlike C, Rust statically prevents you from ever reading them until you do: fn main() { let x: i32; println!("{...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
Drop Flags The examples in the previous section introduce an interesting problem for Rust. We have seen that it's possible to conditionally initialize, deinitialize, and reinitialize locations of memory totally safely. For Copy types, this...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
Unchecked Uninitialized Memory One interesting exception to this rule is working with arrays. Safe Rust doesn't permit you to partially initialize an array. When you initialize an array, you can either set every value to the same thing with...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~5 min read
The Perils Of Ownership Based Resource Management (OBRM) OBRM (AKA RAII: Resource Acquisition Is Initialization) is something you'll interact with a lot in Rust. Especially if you use the standard library. Roughly speaking the pattern is as...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
Constructors There is exactly one way to create an instance of a user-defined type: name it, and initialize all its fields at once: struct Foo { a: u8, b: u32, c: bool, } enum Bar { X(u32), Y(bool), } struct Unit; let foo = Foo { a: 0, b: 1...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
"What about the Quote of the Week? I noticed it's missing quite often these days."

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.