2016-03-04 17:37:11 -05:00
|
|
|
//! The Rust Prelude.
|
2014-12-22 09:04:23 -08:00
|
|
|
//!
|
2015-11-11 15:22:23 -05:00
|
|
|
//! 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
|
2016-02-09 11:47:42 -05:00
|
|
|
//! things, particularly traits, which are used in almost every single Rust
|
2015-11-11 15:22:23 -05:00
|
|
|
//! program.
|
|
|
|
|
//!
|
|
|
|
|
//! # 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.
|
|
|
|
|
//!
|
2020-08-10 19:48:04 +02:00
|
|
|
//! [`std::io::prelude`]: crate::io::prelude
|
2015-11-11 15:22:23 -05:00
|
|
|
//!
|
2015-12-17 20:57:14 +02:00
|
|
|
//! The difference between 'the prelude' and these other preludes is that they
|
2015-11-11 15:22:23 -05:00
|
|
|
//! are not automatically `use`'d, and must be imported manually. This is still
|
2016-02-08 12:04:23 -06:00
|
|
|
//! easier than importing all of their constituent components.
|
2015-11-11 15:22:23 -05:00
|
|
|
//!
|
|
|
|
|
//! # Prelude contents
|
2015-07-11 12:12:19 -07:00
|
|
|
//!
|
|
|
|
|
//! The current version of the prelude (version 1) lives in
|
2018-01-12 16:41:25 -05:00
|
|
|
//! [`std::prelude::v1`], and re-exports the following.
|
2015-07-11 12:12:19 -07:00
|
|
|
//!
|
2019-01-17 00:39:15 +01:00
|
|
|
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}. The
|
|
|
|
|
//! marker traits indicate fundamental properties of types.
|
2015-11-11 15:22:23 -05:00
|
|
|
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}. Various
|
2016-02-10 22:28:32 -05:00
|
|
|
//! operations for both destructors and overloading `()`.
|
2017-04-06 12:57:40 +01:00
|
|
|
//! * [`std::mem`]::[`drop`][`mem::drop`], a convenience function for explicitly
|
|
|
|
|
//! dropping a value.
|
2015-11-11 15:22:23 -05:00
|
|
|
//! * [`std::boxed`]::[`Box`], a way to allocate values on the heap.
|
|
|
|
|
//! * [`std::borrow`]::[`ToOwned`], The conversion trait that defines
|
2017-03-12 14:04:52 -04:00
|
|
|
//! [`to_owned`], the generic method for creating an owned type from a
|
2015-11-11 15:22:23 -05:00
|
|
|
//! borrowed type.
|
2017-04-06 12:57:40 +01:00
|
|
|
//! * [`std::clone`]::[`Clone`], the ubiquitous trait that defines
|
|
|
|
|
//! [`clone`][`Clone::clone`], the method for producing a copy of a value.
|
2015-11-11 15:22:23 -05:00
|
|
|
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`] }. The
|
|
|
|
|
//! comparison traits, which implement the comparison operators and are often
|
|
|
|
|
//! seen in trait bounds.
|
|
|
|
|
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}. Generic
|
|
|
|
|
//! conversions, 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 various
|
|
|
|
|
//! kinds.
|
2020-08-10 19:48:04 +02:00
|
|
|
//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}. A
|
|
|
|
|
//! type which expresses the presence or absence of a value. This type is so
|
|
|
|
|
//! commonly used, its variants are also exported.
|
|
|
|
|
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}. A type
|
|
|
|
|
//! for functions that may succeed or fail. Like [`Option`], its variants are
|
|
|
|
|
//! exported as well.
|
2015-11-11 15:22:23 -05:00
|
|
|
//! * [`std::string`]::{[`String`], [`ToString`]}, heap allocated strings.
|
2020-08-10 19:48:04 +02:00
|
|
|
//! * [`std::vec`]::[`Vec`], a growable, heap-allocated
|
2015-11-11 15:22:23 -05:00
|
|
|
//! vector.
|
2015-07-11 12:12:19 -07:00
|
|
|
//!
|
2020-08-10 19:48:04 +02:00
|
|
|
//! [`mem::drop`]: crate::mem::drop
|
|
|
|
|
//! [`std::borrow`]: crate::borrow
|
|
|
|
|
//! [`std::boxed`]: crate::boxed
|
|
|
|
|
//! [`std::clone`]: crate::clone
|
|
|
|
|
//! [`std::cmp`]: crate::cmp
|
|
|
|
|
//! [`std::convert`]: crate::convert
|
|
|
|
|
//! [`std::default`]: crate::default
|
|
|
|
|
//! [`std::iter`]: crate::iter
|
|
|
|
|
//! [`std::marker`]: crate::marker
|
|
|
|
|
//! [`std::mem`]: crate::mem
|
|
|
|
|
//! [`std::ops`]: crate::ops
|
|
|
|
|
//! [`std::option`]: crate::option
|
|
|
|
|
//! [`std::prelude::v1`]: v1
|
|
|
|
|
//! [`std::result`]: crate::result
|
|
|
|
|
//! [`std::slice`]: crate::slice
|
|
|
|
|
//! [`std::string`]: crate::string
|
2020-09-01 23:39:16 -04:00
|
|
|
//! [`std::vec`]: crate::vec!
|
2020-08-10 19:48:04 +02:00
|
|
|
//! [`to_owned`]: crate::borrow::ToOwned::to_owned
|
2019-01-23 03:55:37 +00:00
|
|
|
//! [book-closures]: ../../book/ch13-01-closures.html
|
|
|
|
|
//! [book-dtor]: ../../book/ch15-03-drop.html
|
|
|
|
|
//! [book-enums]: ../../book/ch06-01-defining-an-enum.html
|
|
|
|
|
//! [book-iter]: ../../book/ch13-02-iterators.html
|
2014-12-22 09:04:23 -08:00
|
|
|
|
2015-01-23 21:48:20 -08:00
|
|
|
#![stable(feature = "rust1", since = "1.0.0")]
|
2015-01-04 23:40:07 -08:00
|
|
|
|
2014-12-22 09:04:23 -08:00
|
|
|
pub mod v1;
|