You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[`macro_use` prelude].Both [`core`] and [`std`] areaddedtothe [extern
87
-
prelude].
84
+
The*`no_std` [attribute][attributes]*causesthe [`std`] cratetonotbelinkedautomatically, the [standardlibraryprelude] toinsteaduse the `core` prelude, and the [`macro_use` prelude] to instead use the macros exported from the `core` crate.
85
+
86
+
> [!EXAMPLE]
87
+
> <!-- ignore: test infrastructure can't handle no_std -->
88
+
> ```rust,ignore
89
+
> #![no_std]
90
+
> ```
91
+
92
+
> [!NOTE]
93
+
> Using `no_std` is useful when either the crate is targeting a platform that does not support the standard library or is purposefully not using the capabilities of the standard library.Those capabilities are mainly dynamic memory allocation (e.g. `Box` and `Vec`) and file and network capabilities (e.g. `std::fs` and `std::io`).
94
+
95
+
> [!WARNING]
96
+
> Using `no_std` does not prevent the standard library from being linked.It is still valid to write `externcrate std` in the crate or in one of its dependencies; thiswillcausethecompilertolinkthe `std` crateintotheprogram.
The `no_std` attribute changes the [standard library prelude] to use the `core` prelude instead of the `std` prelude.
102
112
103
-
> [!NOTE]
104
-
> Usingthecorepreludeoverthestandardpreludeisusefulwheneitherthecrateistargetingaplatformthatdoesnotsupportthestandardlibraryorispurposefullynotusingthecapabilitiesofthestandardlibrary.Thosecapabilitiesaremainlydynamicmemoryallocation (e.g. `Box` and `Vec`) andfileandnetworkcapabilities (e.g. `std::fs` and `std::io`).
113
+
r[names.preludes.extern.no_std.macro_use]
114
+
By default, all macros exported from the `std` crate are added to the [`macro_use` prelude].Ifthe `no_std` attribute is specified, then all macros exported from the `core` crate are placed into the [`macro_use` prelude] instead.
105
115
106
-
> [!WARNING]
107
-
> Using `no_std` doesnotpreventthestandardlibraryfrombeinglinkedin.Itisstillvalidtoput `externcrate std;` intothecrateanddependenciescanalsolinkitin.
116
+
r[names.preludes.extern.no_std.edition2018]
117
+
> [!EDITION-2018]
118
+
> Before the 2018 edition, `std` is injected into the crate root by default.If `no_std` is specified, `core` is injected instead.Starting with the 2018 edition, regardless of `no_std` being specified, neither is injected into the crate root.
0 commit comments