2020Rust's semantics obey a * phase distinction* between compile-time and
2121run-time.[ ^ phase-distinction ] Semantic rules that have a * static
2222interpretation* govern the success or failure of compilation, while
23- semantic rules
24- that have a * dynamic interpretation* govern the behavior of the program at
25- run-time.
23+ semantic rules that have a * dynamic interpretation* govern the behavior of the
24+ program at run-time.
2625
2726The compilation model centers on artifacts called _ crates_ . Each compilation
2827processes a single crate in source form, and if successful, produces a single
@@ -66,22 +65,6 @@ apply to the crate as a whole.
6665#![warn(non_camel_case_types)]
6766```
6867
69- A crate that contains a ` main ` [ function] can be compiled to an executable. If a
70- ` main ` function is present, it must take no arguments, must not declare any
71- [ trait or lifetime bounds] , must not have any [ where clauses] , and its return
72- type must be one of the following:
73-
74- * ` () `
75- * ` Result<(), E> where E: Error `
76- <!-- * `!` -->
77- <!-- * Result<!, E> where E: Error` -->
78-
79- > Note: The implementation of which return types are allowed is determined by
80- > the unstable [ ` Termination ` ] trait.
81-
82- <!-- If the previous section needs updating (from "must take no arguments"
83- onwards, also update it in the attributes.md file, testing section -->
84-
8568The optional [ _ UTF8 byte order mark_ ] (UTF8BOM production) indicates that the
8669file is encoded in UTF8. It can only occur at the beginning of the file and
8770is ignored by the compiler.
@@ -100,6 +83,48 @@ fn main() {
10083}
10184```
10285
86+ ## Preludes and ` no_std `
87+
88+ All crates have a * prelude* that automatically inserts names from a specific
89+ module, the * prelude module* , into scope of each [ module] and an [ `extern
90+ crate] ` into the crate root module. By default, the * standard prelude* is used.
91+ The linked crate is [ ` std ` ] and the prelude module is [ ` std::prelude::v1 ` ] .
92+
93+ The prelude can be changed to the * core prelude* by using the ` no_std `
94+ [ attribute] on the root crate module. The linked crate is [ ` core ` ] and the
95+ prelude module is [ ` core::prelude::v1 ` ] . Using the core prelude over the
96+ standard prelude is useful when either the crate is targeting a platform that
97+ does not support the standard library or is purposefully not using the
98+ capabilities of the standard library. Those capabilities are mainly dynamic
99+ memory allocation (e.g. ` Box ` and ` Vec ` ) and file and network capabilities (e.g.
100+ ` std::fs ` and ` std::io ` ).
101+
102+ <div class =" warning " >
103+
104+ Warning: Using ` no_std ` does not prevent the standard library from being linked
105+ in. It is still valid to put ` extern crate std; ` into the crate and dependencies
106+ can also link it in.
107+
108+ </div >
109+
110+ ## Main Functions
111+
112+ A crate that contains a ` main ` [ function] can be compiled to an executable. If a
113+ ` main ` function is present, it must take no arguments, must not declare any
114+ [ trait or lifetime bounds] , must not have any [ where clauses] , and its return
115+ type must be one of the following:
116+
117+ * ` () `
118+ * ` Result<(), E> where E: Error `
119+ <!-- * `!` -->
120+ <!-- * Result<!, E> where E: Error` -->
121+
122+ > Note: The implementation of which return types are allowed is determined by
123+ > the unstable [ ` Termination ` ] trait.
124+
125+ <!-- If the previous section needs updating (from "must take no arguments"
126+ onwards, also update it in the attributes.md file, testing section -->
127+
103128[ ^ phase-distinction ] : This distinction would also exist in an interpreter.
104129 Static checks like syntactic analysis, type checking, and lints should
105130 happen before the program is executed regardless of when it is executed.
@@ -108,15 +133,21 @@ fn main() {
108133 ECMA-335 CLI model, a * library* in the SML/NJ Compilation Manager, a * unit*
109134 in the Owens and Flatt module system, or a * configuration* in Mesa.
110135
111- [ module ] : items/modules.html
112- [ module path ] : paths.html
113- [ attributes ] : attributes.html
114- [ unit ] : types.html#tuple-types
115136[ _InnerAttribute_ ] : attributes.html
116137[ _Item_ ] : items.html
117138[ _shebang_ ] : https://en.wikipedia.org/wiki/Shebang_(Unix)
118139[ _utf8 byte order mark_ ] : https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
119- [ function ] : items/functions.html
120140[ `Termination` ] : ../std/process/trait.Termination.html
121- [ where clauses ] : items/generics.html#where-clauses
141+ [ `core` ] : ../core/index.html
142+ [ `core::prelude::v1` ] : ../core/preludce.index.html
143+ [ `std` ] : ../std/index.html
144+ [ `std::prelude::v1` ] : ../std/prelude/index.html
145+ [ `use` declaration ] : items/use-declarations.html
146+ [ attribute ] : attributes.html
147+ [ attributes ] : attributes.html
148+ [ function ] : items/functions.html
149+ [ module ] : items/modules.html
150+ [ module path ] : paths.html
122151[ trait or lifetime bounds ] : trait-bounds.html
152+ [ unit ] : types.html#tuple-types
153+ [ where clauses ] : items/generics.html#where-clauses
0 commit comments