3 //! Rust comes with a variety of things in its standard library. However, if
4 //! you had to manually import every single thing that you used, it would be
5 //! very verbose. But importing a lot of things that a program never uses isn't
6 //! good either. A balance needs to be struck.
8 //! The *prelude* is the list of things that Rust automatically imports into
9 //! every Rust program. It's kept as small as possible, and is focused on
10 //! things, particularly traits, which are used in almost every single Rust
15 //! Preludes can be seen as a pattern to make using multiple types more
16 //! convenient. As such, you'll find other preludes in the standard library,
17 //! such as [`std::io::prelude`]. Various libraries in the Rust ecosystem may
18 //! also define their own preludes.
20 //! [`std::io::prelude`]: crate::io::prelude
22 //! The difference between 'the prelude' and these other preludes is that they
23 //! are not automatically `use`'d, and must be imported manually. This is still
24 //! easier than importing all of their constituent components.
26 //! # Prelude contents
28 //! The first version of the prelude is used in Rust 2015 and Rust 2018,
29 //! and lives in [`std::prelude::v1`].
30 //! [`std::prelude::rust_2015`] and [`std::prelude::rust_2018`] re-export this prelude.
31 //! It re-exports the following:
33 //! * <code>[std::marker]::{[Copy], [Send], [Sized], [Sync], [Unpin]}</code>,
34 //! marker traits that indicate fundamental properties of types.
35 //! * <code>[std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}</code>, various
36 //! operations for both destructors and overloading `()`.
37 //! * <code>[std::mem]::[drop][mem::drop]</code>, a convenience function for explicitly
39 //! * <code>[std::boxed]::[Box]</code>, a way to allocate values on the heap.
40 //! * <code>[std::borrow]::[ToOwned]</code>, the conversion trait that defines
41 //! [`to_owned`], the generic method for creating an owned type from a
43 //! * <code>[std::clone]::[Clone]</code>, the ubiquitous trait that defines
44 //! [`clone`][Clone::clone], the method for producing a copy of a value.
45 //! * <code>[std::cmp]::{[PartialEq], [PartialOrd], [Eq], [Ord]}</code>, the
46 //! comparison traits, which implement the comparison operators and are often
47 //! seen in trait bounds.
48 //! * <code>[std::convert]::{[AsRef], [AsMut], [Into], [From]}</code>, generic
49 //! conversions, used by savvy API authors to create overloaded methods.
50 //! * <code>[std::default]::[Default]</code>, types that have default values.
51 //! * <code>[std::iter]::{[Iterator], [Extend], [IntoIterator], [DoubleEndedIterator], [ExactSizeIterator]}</code>,
52 //! iterators of various
54 //! * <code>[std::option]::[Option]::{[self][Option], [Some], [None]}</code>, a
55 //! type which expresses the presence or absence of a value. This type is so
56 //! commonly used, its variants are also exported.
57 //! * <code>[std::result]::[Result]::{[self][Result], [Ok], [Err]}</code>, a type
58 //! for functions that may succeed or fail. Like [`Option`], its variants are
60 //! * <code>[std::string]::{[String], [ToString]}</code>, heap-allocated strings.
61 //! * <code>[std::vec]::[Vec]</code>, a growable, heap-allocated vector.
63 //! The prelude used in Rust 2021, [`std::prelude::rust_2021`], includes all of the above,
64 //! and in addition re-exports:
66 //! * <code>[std::convert]::{[TryFrom], [TryInto]}</code>,
67 //! * <code>[std::iter]::[FromIterator]</code>.
69 //! [mem::drop]: crate::mem::drop
70 //! [std::borrow]: crate::borrow
71 //! [std::boxed]: crate::boxed
72 //! [std::clone]: crate::clone
73 //! [std::cmp]: crate::cmp
74 //! [std::convert]: crate::convert
75 //! [std::default]: crate::default
76 //! [std::iter]: crate::iter
77 //! [std::marker]: crate::marker
78 //! [std::mem]: crate::mem
79 //! [std::ops]: crate::ops
80 //! [std::option]: crate::option
81 //! [`std::prelude::v1`]: v1
82 //! [`std::prelude::rust_2015`]: rust_2015
83 //! [`std::prelude::rust_2018`]: rust_2018
84 //! [`std::prelude::rust_2021`]: rust_2021
85 //! [std::result]: crate::result
86 //! [std::slice]: crate::slice
87 //! [std::string]: crate::string
88 //! [std::vec]: mod@crate::vec
89 //! [TryFrom]: crate::convert::TryFrom
90 //! [TryInto]: crate::convert::TryInto
91 //! [FromIterator]: crate::iter::FromIterator
92 //! [`to_owned`]: crate::borrow::ToOwned::to_owned
93 //! [book-closures]: ../../book/ch13-01-closures.html
94 //! [book-dtor]: ../../book/ch15-03-drop.html
95 //! [book-enums]: ../../book/ch06-01-defining-an-enum.html
96 //! [book-iter]: ../../book/ch13-02-iterators.html
98 #![stable(feature = "rust1", since = "1.0.0")]
102 /// The 2015 version of the prelude of The Rust Standard Library.
104 /// See the [module-level documentation](self) for more.
105 #[stable(feature = "prelude_2015", since = "1.55.0")]
107 #[stable(feature = "prelude_2015", since = "1.55.0")]
109 pub use super::v1::*;
112 /// The 2018 version of the prelude of The Rust Standard Library.
114 /// See the [module-level documentation](self) for more.
115 #[stable(feature = "prelude_2018", since = "1.55.0")]
117 #[stable(feature = "prelude_2018", since = "1.55.0")]
119 pub use super::v1::*;
122 /// The 2021 version of the prelude of The Rust Standard Library.
124 /// See the [module-level documentation](self) for more.
125 #[stable(feature = "prelude_2021", since = "1.55.0")]
127 #[stable(feature = "prelude_2021", since = "1.55.0")]
129 pub use super::v1::*;
131 #[stable(feature = "prelude_2021", since = "1.55.0")]
133 pub use core::prelude::rust_2021::*;
136 /// The 2024 version of the prelude of The Rust Standard Library.
138 /// See the [module-level documentation](self) for more.
139 #[unstable(feature = "prelude_2024", issue = "none")]
141 #[unstable(feature = "prelude_2024", issue = "none")]
143 pub use super::v1::*;
145 #[unstable(feature = "prelude_2024", issue = "none")]
147 pub use core::prelude::rust_2024::*;