Module std::prelude 1.0.0
[−]
[src]
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
use std::prelude::v1::*;Run
into every module.
Other preludes
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, such as 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.
Prelude contents
The current version of the prelude (version 1) lives in std::prelude::v1, and reexports the following.
std::marker::{Copy,Send,Sized,Sync}. The markertraits indicate fundamental properties of types.std::ops::{Drop,Fn,FnMut,FnOnce}. Variousoperations for both destructors and overloading().std::mem::drop, a convenience function for explicitly dropping avalue.std::boxed::Box, a way to allocate values on the heap.std::borrow::ToOwned, The conversion trait that definesto_owned, the generic method for creating an owned type from aborrowed type.std::clone::Clone, the ubiquitous trait that definesclone,the method for producing a copy of a value.std::cmp::{PartialEq,PartialOrd,Eq,Ord}. Thecomparison traits, which implement the comparison operators and are oftenseen in trait bounds.std::convert::{AsRef,AsMut,Into,From}. Genericconversions, used by savvy API authors to create overloaded methods.std::default::Default, types that have default values.std::iter::{Iterator,Extend,IntoIterator,DoubleEndedIterator,ExactSizeIterator}. Iterators of variouskinds.std::option::Option::{self,Some,None}. A type whichexpresses the presence or absence of a value. This type is so commonlyused, its variants are also exported.std::result::Result::{self,Ok,Err}. A type for functionsthat may succeed or fail. LikeOption, its variants are exported aswell.std::slice::SliceConcatExt, a trait that exists for technicalreasons, but shouldn't have to exist. It provides a few useful methods onslices.std::string::{String,ToString}, heap allocated strings.std::vec::Vec, a growable, heap-allocatedvector.
Modules
| v1 |
The first version of the prelude of The Rust Standard Library. |