1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! # Rust Prelude
//!
//! Rust 在其标准库中附带了许多东西。但是,如果您必须手动导入所用的每件事,那将非常冗长。
//! 但是,导入很多程序从未使用过的东西也是不好的。
//! 需要取得平衡。
//!
//! *prelude* 是 Rust 自动导入每个 Rust 程序的内容的列表。
//! 它保持尽可能的小,并专注于几乎在每个 Rust 程序中使用的东西,尤其是 traits。
//!
//! # 其他 preludes
//!
//! preludes 可以看作是使使用多种类型更方便的一种模式。
//! 这样,您将在标准库中找到其他 preludes,例如 [`std::io::prelude`]。Rust 生态系统中的各种库也可以定义自己的 preludes。
//!
//! [`std::io::prelude`]: crate::io::prelude
//!
//! `prelude` 和其他 preludes 之间的区别是它们不会自动 `use`,而必须手动导入。
//! 这仍然比导入其所有组成组件容易。
//!
//! # Prelude 的内容
//!
//! prelude 的第一个版本用于 Rust 2015 和 Rust 2018,并存在于 [`std::prelude::v1`] 中。
//! [`std::prelude::rust_2015`] 并且 [`std::prelude::rust_2018`] 重导出了这个 prelude。
//! 它重导出以下内容:
//!
//! * <code>[std::marker]::{[Copy], [Send], [Sized], [Sync], [Unpin]}</code>,指示类型基本属性的标记 traits。
//! * <code>[std::ops]::{[Drop], [Fn], [FnMut], [FnOnce]}</code>,用于析构函数和重载 `()` 的各种操作。
//! * <code>[std::mem]::[drop][mem::drop]</code>,一种用于明确丢弃值的便利功能。
//! * <code>[std::boxed]::[Box]</code>,一种在堆上分配值的方法。
//! * <code>[std::borrow]::[ToOwned]</code>,定义 [`to_owned`] 的转换 trait,泛型从借用类型创建拥有所有权的类型的方法。
//! * <code>[std::clone]::[Clone]</code>,无处不在的 trait 定义了 [`clone`][Clone::clone],生成值的副本的方法。
//! * <code>[std::cmp]::{[PartialEq], [PartialOrd], [Eq], [Ord]}</code>,比较 traits,实现比较一致,经常在 trait bounds 中看到。
//!
//! * <code>[std::convert]::{[AsRef], [AsMut], [Into], [From]}</code>, 泛型转换,由精明的 API 作者用来创建重载方法。
//! * <code>[std::default]::[Default]</code>,具有默认值的类型。
//! * <code>[std::iter]::{[Iterator], [Extend], [IntoIterator], [DoubleEndedIterator], [ExactSizeIterator]}</code>,各种迭代器。
//! * <code>[std::option]::[Option]::{[self][Option], [Some], [None]}</code>,一种表示值存在与否的类型。
//! 这种类型非常常用,其成员也已导出。
//! * <code>[std::result]::[Result]::{[self][Result], [Ok], [Err]}</code>,一种可能成功或失败的函数类型。
//! 像 [`Option`] 一样,它的成员也被导出。
//! * <code>[std::string]::{[String], [ToString]}</code>,堆分配的字符串。
//! * <code>[std::vec]::[Vec]</code>,一个可增长的、堆分配的 vector。
//!
//! Rust 2021 [`std::prelude::rust_2021`] 中使用的 prelude,包含了以上所有内容,另外还有重导出:
//!
//! * <code>[std::convert]::{[TryFrom], [TryInto]}</code>,
//! * <code>[std::iter]::[FromIterator]</code>.
//!
//! [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::prelude::rust_2015`]: rust_2015
//! [`std::prelude::rust_2018`]: rust_2018
//! [`std::prelude::rust_2021`]: rust_2021
//! [std::result]: crate::result
//! [std::slice]: crate::slice
//! [std::string]: crate::string
//! [std::vec]: mod@crate::vec
//! [TryFrom]: crate::convert::TryFrom
//! [TryInto]: crate::convert::TryInto
//! [FromIterator]: crate::iter::FromIterator
//! [`to_owned`]: crate::borrow::ToOwned::to_owned
//! [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
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!
//!

#![stable(feature = "rust1", since = "1.0.0")]

pub mod v1;

/// Rust 标准库的 prelude 的 2015 版本。
///
/// 有关更多信息,请参见 [module-level documentation](self)。
#[stable(feature = "prelude_2015", since = "1.55.0")]
pub mod rust_2015 {
    #[stable(feature = "prelude_2015", since = "1.55.0")]
    #[doc(no_inline)]
    pub use super::v1::*;
}

/// Rust 标准库的 prelude 2018 版本。
///
/// 有关更多信息,请参见 [module-level documentation](self)。
#[stable(feature = "prelude_2018", since = "1.55.0")]
pub mod rust_2018 {
    #[stable(feature = "prelude_2018", since = "1.55.0")]
    #[doc(no_inline)]
    pub use super::v1::*;
}

/// Rust 标准库的 prelude 的 2021 版本。
///
/// 有关更多信息,请参见 [module-level documentation](self)。
#[stable(feature = "prelude_2021", since = "1.55.0")]
pub mod rust_2021 {
    #[stable(feature = "prelude_2021", since = "1.55.0")]
    #[doc(no_inline)]
    pub use super::v1::*;

    #[stable(feature = "prelude_2021", since = "1.55.0")]
    #[doc(no_inline)]
    pub use core::prelude::rust_2021::*;
}