Rust Search

Find the best content on Rust, curated by the community; a search engine for Rustaceans.
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~3 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~7 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~8 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~7 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~1 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~5 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~2 min read
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'...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~7 min read
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...
doc.rust-lang.org The Rustonomicon Book 2024-01-01 ~3 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
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
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
"I might suspect that if you are lumping all statically-typed languages into a single bucket without making particular distinction among them, then you..."

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.