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.
|
|
|
|
|
//!
|
|
|
|
|
//! On a technical level, Rust inserts
|
2014-12-22 09:04:23 -08:00
|
|
|
//!
|
2017-06-20 15:15:16 +08:00
|
|
|
//! ```
|
2017-06-24 17:48:27 +09:00
|
|
|
//! # #[allow(unused_extern_crates)]
|
2014-12-22 09:04:23 -08:00
|
|
|
//! extern crate std;
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
2015-11-12 13:20:48 +05:30
|
|
|
//! into the crate root of every crate, and
|
2014-12-22 09:04:23 -08:00
|
|
|
//!
|
2017-06-20 15:15:16 +08:00
|
|
|
//! ```
|
|
|
|
|
//! # #[allow(unused_imports)]
|
2014-12-22 09:04:23 -08:00
|
|
|
//! use std::prelude::v1::*;
|
|
|
|
|
//! ```
|
|
|
|
|
//!
|
2015-11-11 15:22:23 -05:00
|
|
|
//! 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.
|
|
|
|
|
//!
|
|
|
|
|
//! [`std::io::prelude`]: ../io/prelude/index.html
|
|
|
|
|
//!
|
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.
|
|
|
|
|
//! * [`std::option`]::[`Option`]::{`self`, `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`, `Ok`, `Err`}. A type for functions
|
|
|
|
|
//! that may succeed or fail. Like [`Option`], its variants are exported as
|
|
|
|
|
//! well.
|
|
|
|
|
//! * [`std::slice`]::[`SliceConcatExt`], a trait that exists for technical
|
|
|
|
|
//! reasons, but shouldn't have to exist. It provides a few useful methods on
|
|
|
|
|
//! slices.
|
|
|
|
|
//! * [`std::string`]::{[`String`], [`ToString`]}, heap allocated strings.
|
|
|
|
|
//! * [`std::vec`]::[`Vec`](../vec/struct.Vec.html), a growable, heap-allocated
|
|
|
|
|
//! vector.
|
2015-07-11 12:12:19 -07:00
|
|
|
//!
|
2015-11-11 15:22:23 -05:00
|
|
|
//! [`AsMut`]: ../convert/trait.AsMut.html
|
|
|
|
|
//! [`AsRef`]: ../convert/trait.AsRef.html
|
|
|
|
|
//! [`Box`]: ../boxed/struct.Box.html
|
|
|
|
|
//! [`Clone`]: ../clone/trait.Clone.html
|
|
|
|
|
//! [`Copy`]: ../marker/trait.Copy.html
|
|
|
|
|
//! [`Default`]: ../default/trait.Default.html
|
|
|
|
|
//! [`DoubleEndedIterator`]: ../iter/trait.DoubleEndedIterator.html
|
|
|
|
|
//! [`Drop`]: ../ops/trait.Drop.html
|
|
|
|
|
//! [`Eq`]: ../cmp/trait.Eq.html
|
|
|
|
|
//! [`ExactSizeIterator`]: ../iter/trait.ExactSizeIterator.html
|
|
|
|
|
//! [`Extend`]: ../iter/trait.Extend.html
|
|
|
|
|
//! [`FnMut`]: ../ops/trait.FnMut.html
|
|
|
|
|
//! [`FnOnce`]: ../ops/trait.FnOnce.html
|
|
|
|
|
//! [`Fn`]: ../ops/trait.Fn.html
|
|
|
|
|
//! [`From`]: ../convert/trait.From.html
|
|
|
|
|
//! [`IntoIterator`]: ../iter/trait.IntoIterator.html
|
|
|
|
|
//! [`Into`]: ../convert/trait.Into.html
|
|
|
|
|
//! [`Iterator`]: ../iter/trait.Iterator.html
|
|
|
|
|
//! [`Option`]: ../option/enum.Option.html
|
|
|
|
|
//! [`Ord`]: ../cmp/trait.Ord.html
|
|
|
|
|
//! [`PartialEq`]: ../cmp/trait.PartialEq.html
|
|
|
|
|
//! [`PartialOrd`]: ../cmp/trait.PartialOrd.html
|
|
|
|
|
//! [`Result`]: ../result/enum.Result.html
|
|
|
|
|
//! [`Send`]: ../marker/trait.Send.html
|
|
|
|
|
//! [`Sized`]: ../marker/trait.Sized.html
|
|
|
|
|
//! [`SliceConcatExt`]: ../slice/trait.SliceConcatExt.html
|
|
|
|
|
//! [`String`]: ../string/struct.String.html
|
|
|
|
|
//! [`Sync`]: ../marker/trait.Sync.html
|
|
|
|
|
//! [`ToOwned`]: ../borrow/trait.ToOwned.html
|
|
|
|
|
//! [`ToString`]: ../string/trait.ToString.html
|
2019-01-17 00:39:15 +01:00
|
|
|
//! [`Unpin`]: ../marker/trait.Unpin.html
|
2015-11-11 15:22:23 -05:00
|
|
|
//! [`Vec`]: ../vec/struct.Vec.html
|
2017-04-06 12:57:40 +01:00
|
|
|
//! [`Clone::clone`]: ../clone/trait.Clone.html#tymethod.clone
|
|
|
|
|
//! [`mem::drop`]: ../mem/fn.drop.html
|
2015-11-11 15:22:23 -05:00
|
|
|
//! [`std::borrow`]: ../borrow/index.html
|
|
|
|
|
//! [`std::boxed`]: ../boxed/index.html
|
|
|
|
|
//! [`std::clone`]: ../clone/index.html
|
|
|
|
|
//! [`std::cmp`]: ../cmp/index.html
|
|
|
|
|
//! [`std::convert`]: ../convert/index.html
|
|
|
|
|
//! [`std::default`]: ../default/index.html
|
|
|
|
|
//! [`std::iter`]: ../iter/index.html
|
|
|
|
|
//! [`std::marker`]: ../marker/index.html
|
|
|
|
|
//! [`std::mem`]: ../mem/index.html
|
|
|
|
|
//! [`std::ops`]: ../ops/index.html
|
|
|
|
|
//! [`std::option`]: ../option/index.html
|
|
|
|
|
//! [`std::prelude::v1`]: v1/index.html
|
|
|
|
|
//! [`std::result`]: ../result/index.html
|
|
|
|
|
//! [`std::slice`]: ../slice/index.html
|
|
|
|
|
//! [`std::string`]: ../string/index.html
|
|
|
|
|
//! [`std::vec`]: ../vec/index.html
|
2017-03-12 14:04:52 -04:00
|
|
|
//! [`to_owned`]: ../borrow/trait.ToOwned.html#tymethod.to_owned
|
2017-06-13 01:30:08 +09:00
|
|
|
//! [book-closures]: ../../book/first-edition/closures.html
|
|
|
|
|
//! [book-dtor]: ../../book/first-edition/drop.html
|
|
|
|
|
//! [book-enums]: ../../book/first-edition/enums.html
|
|
|
|
|
//! [book-iter]: ../../book/first-edition/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;
|