2021-01-05 17:52:24 -08: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
|
2020-12-17 21:17:43 -08:00
|
|
|
//! [`std::prelude::v1`], and re-exports the following:
|
2015-07-11 12:12:19 -07:00
|
|
|
//!
|
2020-12-18 14:58:10 -08:00
|
|
|
//! * [`std::marker`]::{[`Copy`], [`Send`], [`Sized`], [`Sync`], [`Unpin`]}:
|
2021-01-05 17:51:27 -08:00
|
|
|
//! marker traits that indicate fundamental properties of types.
|
|
|
|
|
//! * [`std::ops`]::{[`Drop`], [`Fn`], [`FnMut`], [`FnOnce`]}: various
|
2016-02-10 22:28:32 -05:00
|
|
|
//! operations for both destructors and overloading `()`.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::mem`]::[`drop`][`mem::drop`]: a convenience function for explicitly
|
2017-04-06 12:57:40 +01:00
|
|
|
//! dropping a value.
|
2021-01-05 17:51:27 -08: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.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::clone`]::[`Clone`]: the ubiquitous trait that defines
|
2017-04-06 12:57:40 +01:00
|
|
|
//! [`clone`][`Clone::clone`], the method for producing a copy of a value.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::cmp`]::{[`PartialEq`], [`PartialOrd`], [`Eq`], [`Ord`]}: the
|
2015-11-11 15:22:23 -05:00
|
|
|
//! comparison traits, which implement the comparison operators and are often
|
|
|
|
|
//! seen in trait bounds.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::convert`]::{[`AsRef`], [`AsMut`], [`Into`], [`From`]}: generic
|
2015-11-11 15:22:23 -05:00
|
|
|
//! conversions, used by savvy API authors to create overloaded methods.
|
|
|
|
|
//! * [`std::default`]::[`Default`], types that have default values.
|
2020-12-18 14:58:10 -08:00
|
|
|
//! * [`std::iter`]::{[`Iterator`], [`Extend`], [`IntoIterator`],
|
2021-01-05 17:51:27 -08:00
|
|
|
//! [`DoubleEndedIterator`], [`ExactSizeIterator`]}: iterators of various
|
2015-11-11 15:22:23 -05:00
|
|
|
//! kinds.
|
2020-12-17 21:17:43 -08:00
|
|
|
//! * [`std::option`]::[`Option`]::{[`self`][`Option`], [`Some`], [`None`]}, a
|
2020-08-10 19:48:04 +02:00
|
|
|
//! type which expresses the presence or absence of a value. This type is so
|
|
|
|
|
//! commonly used, its variants are also exported.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::result`]::[`Result`]::{[`self`][`Result`], [`Ok`], [`Err`]}: a type
|
2020-08-10 19:48:04 +02:00
|
|
|
//! for functions that may succeed or fail. Like [`Option`], its variants are
|
|
|
|
|
//! exported as well.
|
2021-01-05 17:51:27 -08:00
|
|
|
//! * [`std::string`]::{[`String`], [`ToString`]}: heap-allocated strings.
|
|
|
|
|
//! * [`std::vec`]::[`Vec`]: a growable, heap-allocated 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-02 17:36:56 -04:00
|
|
|
//! [`std::vec`]: mod@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;
|