The Rust Prelude.
Rust comes with a variety of things in its standard library. However, if you had to manually import every single thing that you used, it would be very verbose. But importing a lot of things that a program never uses isn't good either. A balance needs to be struck.
The prelude is the list of things that Rust automatically imports into every Rust program. It's kept as small as possible, and is focused on things, particularly traits, which are used in almost every single Rust program.
On a technical level, Rust inserts
extern crate std;Run
into the crate root of every crate, and
into every module.
Preludes can be seen as a pattern to make using multiple types more
convenient. As such, you'll find other preludes in the standard library,
std::io::prelude. Various libraries in the Rust ecosystem may
also define their own preludes.
The difference between 'the prelude' and these other preludes is that they
are not automatically
use'd, and must be imported manually. This is still
easier than importing all of their constituent components.
The current version of the prelude (version 1) lives in
std::prelude::v1, and re-exports the following.
Sync}. The marker traits indicate fundamental properties of types.
FnOnce}. Various operations for both destructors and overloading
drop, a convenience function for explicitly dropping a value.
Box, a way to allocate values on the heap.
ToOwned, The conversion trait that defines
to_owned, the generic method for creating an owned type from a borrowed type.
Clone, the ubiquitous trait that defines
clone, the method for producing a copy of a value.
Ord}. The comparison traits, which implement the comparison operators and are often seen in trait bounds.
From}. Generic conversions, used by savvy API authors to create overloaded methods.
Default, types that have default values.
ExactSizeIterator}. Iterators of various kinds.
None}. A type which expresses the presence or absence of a value. This type is so commonly used, its variants are also exported.
Err}. A type for functions that may succeed or fail. Like
Option, its variants are exported as well.
SliceConcatExt, a trait that exists for technical reasons, but shouldn't have to exist. It provides a few useful methods on slices.
ToString}, heap allocated strings.
Vec, a growable, heap-allocated vector.
The first version of the prelude of The Rust Standard Library.