Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
doc.rust-lang.org
IntoIter Let's move on to writing iterators. iter and iter_mut have already been written for us thanks to The Magic of Deref. However there's two interesting iterators that Vec provides that slices can't: into_iter and drain. IntoIter consu...
The Rustonomicon Book 2024-01-01 ~3 min read
doc.rust-lang.org
Insert and Remove Something not provided by slice is insert and remove, so let's do those next. Insert needs to shift all the elements at the target index to the right by one. To do this we need to use ptr::copy, which is our version of C's...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Deref Alright! We've got a decent minimal stack implemented. We can push, we can pop, and we can clean up after ourselves. However there's a whole mess of functionality we'd reasonably want. In particular, we have a proper array, but none o...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Deallocating Next we should implement Drop so that we don't massively leak tons of resources. The easiest way is to just call pop until it yields None, and then deallocate our buffer. Note that calling pop is unneeded if T: !Drop. In theory...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Push and Pop Alright. We can initialize. We can allocate. Let's actually implement some functionality! Let's start with push. All it needs to do is check if we're full to grow, unconditionally write to the next index, and then increment our...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Allocating Memory Using NonNull throws a wrench in an important feature of Vec (and indeed all of the std collections): creating an empty Vec doesn't actually allocate at all. This is not the same as allocating a zero-sized memory block, wh...
The Rustonomicon Book 2024-01-01 ~7 min read
doc.rust-lang.org
Layout First off, we need to come up with the struct layout. A Vec has three parts: a pointer to the allocation, the size of the allocation, and the number of elements that have been initialized. Naively, this means we just want this design...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Example: Implementing Vec To bring everything together, we're going to write std::Vec from scratch. We will limit ourselves to stable Rust. In particular we won't use any intrinsics that could make our code a little bit nicer or efficient b...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Atomics Rust pretty blatantly just inherits the memory model for atomics from C++20. This is not due to this model being particularly excellent or easy to understand. Indeed, this model is quite complex and known to have several flaws. Rath...
The Rustonomicon Book 2024-01-01 ~8 min read
doc.rust-lang.org
Send and Sync Not everything obeys inherited mutability, though. Some types allow you to have multiple aliases of a location in memory while mutating it. Unless these types use synchronization to manage this access, they are absolutely not...
The Rustonomicon Book 2024-01-01 ~7 min read
doc.rust-lang.org
Data Races and Race Conditions Safe Rust guarantees an absence of data races, which are defined as: • two or more threads concurrently accessing a location of memory • one or more of them is a write • one or more of them is unsynchronized A...
The Rustonomicon Book 2024-01-01 ~2 min read
doc.rust-lang.org
Concurrency and Parallelism Rust as a language doesn't really have an opinion on how to do concurrency or parallelism. The standard library exposes OS threads and blocking sys-calls because everyone has those, and they're uniform enough tha...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Poisoning Although all unsafe code must ensure it has minimal exception safety, not all types ensure maximal exception safety. Even if the type does, your code may ascribe additional meaning to it. For instance, an integer is certainly exce...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
Exception Safety Although programs should use unwinding sparingly, there's a lot of code that can panic. If you unwrap a None, index out of bounds, or divide by 0, your program will panic. On debug builds, every arithmetic operation can pan...
The Rustonomicon Book 2024-01-01 ~5 min read
doc.rust-lang.org
Unwinding Rust has a tiered error-handling scheme: • If something might reasonably be absent, Option is used. • If something goes wrong and can reasonably be handled, Result is used. • If something goes wrong and cannot reasonably be handle...
The Rustonomicon Book 2024-01-01 ~2 min read
doc.rust-lang.org
Leaking Ownership-based resource management is intended to simplify composition. You acquire resources when you create the object, and you release the resources when it gets destroyed. Since destruction is handled for you, it means you can'...
The Rustonomicon Book 2024-01-01 ~7 min read
doc.rust-lang.org
Destructors What the language does provide is full-blown automatic destructors through the Drop trait, which provides the following method: fn drop(&mut self); This method gives the type time to somehow finish what it was doing. After drop...
The Rustonomicon Book 2024-01-01 ~3 min read
doc.rust-lang.org
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...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
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...
The Rustonomicon Book 2024-01-01 ~1 min read
doc.rust-lang.org
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...
The Rustonomicon Book 2024-01-01 ~5 min read
"Rust beginners worrying about lifetimes is like kids worrying about quicksand. Both turn out to be a non-issue in life."

Search tips

Type anything to search across articles, videos (including conference talks), podcasts, research, crates, and Rust API documentation. 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.
Put ! first to open the top result immediately. Quote the whole query for a literal leading bang, as in '!Send'. Bangs elsewhere, such as println!, stay literal. Browser and launcher shortcuts can invoke this directly. See search integrations.
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.