1 | //! # The Rust Standard Library |
2 | //! |
3 | //! The Rust Standard Library is the foundation of portable Rust software, a |
4 | //! set of minimal and battle-tested shared abstractions for the [broader Rust |
5 | //! ecosystem][crates.io]. It offers core types, like [`Vec<T>`] and |
6 | //! [`Option<T>`], library-defined [operations on language |
7 | //! primitives](#primitives), [standard macros](#macros), [I/O] and |
8 | //! [multithreading], among [many other things][other]. |
9 | //! |
10 | //! `std` is available to all Rust crates by default. Therefore, the |
11 | //! standard library can be accessed in [`use`] statements through the path |
12 | //! `std`, as in [`use std::env`]. |
13 | //! |
14 | //! # How to read this documentation |
15 | //! |
16 | //! If you already know the name of what you are looking for, the fastest way to |
17 | //! find it is to use the <a href="#" onclick="window.searchState.focus();">search |
18 | //! bar</a> at the top of the page. |
19 | //! |
20 | //! Otherwise, you may want to jump to one of these useful sections: |
21 | //! |
22 | //! * [`std::*` modules](#modules) |
23 | //! * [Primitive types](#primitives) |
24 | //! * [Standard macros](#macros) |
25 | //! * [The Rust Prelude] |
26 | //! |
27 | //! If this is your first time, the documentation for the standard library is |
28 | //! written to be casually perused. Clicking on interesting things should |
29 | //! generally lead you to interesting places. Still, there are important bits |
30 | //! you don't want to miss, so read on for a tour of the standard library and |
31 | //! its documentation! |
32 | //! |
33 | //! Once you are familiar with the contents of the standard library you may |
34 | //! begin to find the verbosity of the prose distracting. At this stage in your |
35 | //! development you may want to press the `[-]` button near the top of the |
36 | //! page to collapse it into a more skimmable view. |
37 | //! |
38 | //! While you are looking at that `[-]` button also notice the `source` |
39 | //! link. Rust's API documentation comes with the source code and you are |
40 | //! encouraged to read it. The standard library source is generally high |
41 | //! quality and a peek behind the curtains is often enlightening. |
42 | //! |
43 | //! # What is in the standard library documentation? |
44 | //! |
45 | //! First of all, The Rust Standard Library is divided into a number of focused |
46 | //! modules, [all listed further down this page](#modules). These modules are |
47 | //! the bedrock upon which all of Rust is forged, and they have mighty names |
48 | //! like [`std::slice`] and [`std::cmp`]. Modules' documentation typically |
49 | //! includes an overview of the module along with examples, and are a smart |
50 | //! place to start familiarizing yourself with the library. |
51 | //! |
52 | //! Second, implicit methods on [primitive types] are documented here. This can |
53 | //! be a source of confusion for two reasons: |
54 | //! |
55 | //! 1. While primitives are implemented by the compiler, the standard library |
56 | //! implements methods directly on the primitive types (and it is the only |
57 | //! library that does so), which are [documented in the section on |
58 | //! primitives](#primitives). |
59 | //! 2. The standard library exports many modules *with the same name as |
60 | //! primitive types*. These define additional items related to the primitive |
61 | //! type, but not the all-important methods. |
62 | //! |
63 | //! So for example there is a [page for the primitive type |
64 | //! `i32`](primitive::i32) that lists all the methods that can be called on |
65 | //! 32-bit integers (very useful), and there is a [page for the module |
66 | //! `std::i32`] that documents the constant values [`MIN`] and [`MAX`] (rarely |
67 | //! useful). |
68 | //! |
69 | //! Note the documentation for the primitives [`str`] and [`[T]`][prim@slice] (also |
70 | //! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually |
71 | //! calls to methods on [`str`] and [`[T]`][prim@slice] respectively, via [deref |
72 | //! coercions][deref-coercions]. |
73 | //! |
74 | //! Third, the standard library defines [The Rust Prelude], a small collection |
75 | //! of items - mostly traits - that are imported into every module of every |
76 | //! crate. The traits in the prelude are pervasive, making the prelude |
77 | //! documentation a good entry point to learning about the library. |
78 | //! |
79 | //! And finally, the standard library exports a number of standard macros, and |
80 | //! [lists them on this page](#macros) (technically, not all of the standard |
81 | //! macros are defined by the standard library - some are defined by the |
82 | //! compiler - but they are documented here the same). Like the prelude, the |
83 | //! standard macros are imported by default into all crates. |
84 | //! |
85 | //! # Contributing changes to the documentation |
86 | //! |
87 | //! Check out the rust contribution guidelines [here]( |
88 | //! https://rustc-dev-guide.rust-lang.org/contributing.html#writing-documentation). |
89 | //! The source for this documentation can be found on |
90 | //! [GitHub](https://github.com/rust-lang/rust). |
91 | //! To contribute changes, make sure you read the guidelines first, then submit |
92 | //! pull-requests for your suggested changes. |
93 | //! |
94 | //! Contributions are appreciated! If you see a part of the docs that can be |
95 | //! improved, submit a PR, or chat with us first on [Discord][rust-discord] |
96 | //! #docs. |
97 | //! |
98 | //! # A Tour of The Rust Standard Library |
99 | //! |
100 | //! The rest of this crate documentation is dedicated to pointing out notable |
101 | //! features of The Rust Standard Library. |
102 | //! |
103 | //! ## Containers and collections |
104 | //! |
105 | //! The [`option`] and [`result`] modules define optional and error-handling |
106 | //! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines |
107 | //! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to |
108 | //! access collections. |
109 | //! |
110 | //! The standard library exposes three common ways to deal with contiguous |
111 | //! regions of memory: |
112 | //! |
113 | //! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime. |
114 | //! * [`[T; N]`][prim@array] - An inline *array* with a fixed size at compile time. |
115 | //! * [`[T]`][prim@slice] - A dynamically sized *slice* into any other kind of contiguous |
116 | //! storage, whether heap-allocated or not. |
117 | //! |
118 | //! Slices can only be handled through some kind of *pointer*, and as such come |
119 | //! in many flavors such as: |
120 | //! |
121 | //! * `&[T]` - *shared slice* |
122 | //! * `&mut [T]` - *mutable slice* |
123 | //! * [`Box<[T]>`][owned slice] - *owned slice* |
124 | //! |
125 | //! [`str`], a UTF-8 string slice, is a primitive type, and the standard library |
126 | //! defines many methods for it. Rust [`str`]s are typically accessed as |
127 | //! immutable references: `&str`. Use the owned [`String`] for building and |
128 | //! mutating strings. |
129 | //! |
130 | //! For converting to strings use the [`format!`] macro, and for converting from |
131 | //! strings use the [`FromStr`] trait. |
132 | //! |
133 | //! Data may be shared by placing it in a reference-counted box or the [`Rc`] |
134 | //! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated |
135 | //! as well as shared. Likewise, in a concurrent setting it is common to pair an |
136 | //! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same |
137 | //! effect. |
138 | //! |
139 | //! The [`collections`] module defines maps, sets, linked lists and other |
140 | //! typical collection types, including the common [`HashMap<K, V>`]. |
141 | //! |
142 | //! ## Platform abstractions and I/O |
143 | //! |
144 | //! Besides basic data types, the standard library is largely concerned with |
145 | //! abstracting over differences in common platforms, most notably Windows and |
146 | //! Unix derivatives. |
147 | //! |
148 | //! Common types of I/O, including [files], [TCP], and [UDP], are defined in |
149 | //! the [`io`], [`fs`], and [`net`] modules. |
150 | //! |
151 | //! The [`thread`] module contains Rust's threading abstractions. [`sync`] |
152 | //! contains further primitive shared memory types, including [`atomic`] and |
153 | //! [`mpsc`], which contains the channel types for message passing. |
154 | //! |
155 | //! # Use before and after `main()` |
156 | //! |
157 | //! Many parts of the standard library are expected to work before and after `main()`; |
158 | //! but this is not guaranteed or ensured by tests. It is recommended that you write your own tests |
159 | //! and run them on each platform you wish to support. |
160 | //! This means that use of `std` before/after main, especially of features that interact with the |
161 | //! OS or global state, is exempted from stability and portability guarantees and instead only |
162 | //! provided on a best-effort basis. Nevertheless bug reports are appreciated. |
163 | //! |
164 | //! On the other hand `core` and `alloc` are most likely to work in such environments with |
165 | //! the caveat that any hookable behavior such as panics, oom handling or allocators will also |
166 | //! depend on the compatibility of the hooks. |
167 | //! |
168 | //! Some features may also behave differently outside main, e.g. stdio could become unbuffered, |
169 | //! some panics might turn into aborts, backtraces might not get symbolicated or similar. |
170 | //! |
171 | //! Non-exhaustive list of known limitations: |
172 | //! |
173 | //! - after-main use of thread-locals, which also affects additional features: |
174 | //! - [`thread::current()`] |
175 | //! - [`thread::scope()`] |
176 | //! - [`sync::mpsc`] |
177 | //! - before-main stdio file descriptors are not guaranteed to be open on unix platforms |
178 | //! |
179 | //! |
180 | //! [I/O]: io |
181 | //! [`MIN`]: i32::MIN |
182 | //! [`MAX`]: i32::MAX |
183 | //! [page for the module `std::i32`]: crate::i32 |
184 | //! [TCP]: net::TcpStream |
185 | //! [The Rust Prelude]: prelude |
186 | //! [UDP]: net::UdpSocket |
187 | //! [`Arc`]: sync::Arc |
188 | //! [owned slice]: boxed |
189 | //! [`Cell`]: cell::Cell |
190 | //! [`FromStr`]: str::FromStr |
191 | //! [`HashMap<K, V>`]: collections::HashMap |
192 | //! [`Mutex`]: sync::Mutex |
193 | //! [`Option<T>`]: option::Option |
194 | //! [`Rc`]: rc::Rc |
195 | //! [`RefCell`]: cell::RefCell |
196 | //! [`Result<T, E>`]: result::Result |
197 | //! [`Vec<T>`]: vec::Vec |
198 | //! [`atomic`]: sync::atomic |
199 | //! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for |
200 | //! [`str`]: prim@str |
201 | //! [`mpsc`]: sync::mpsc |
202 | //! [`std::cmp`]: cmp |
203 | //! [`std::slice`]: mod@slice |
204 | //! [`use std::env`]: env/index.html |
205 | //! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html |
206 | //! [crates.io]: https://crates.io |
207 | //! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods |
208 | //! [files]: fs::File |
209 | //! [multithreading]: thread |
210 | //! [other]: #what-is-in-the-standard-library-documentation |
211 | //! [primitive types]: ../book/ch03-02-data-types.html |
212 | //! [rust-discord]: https://discord.gg/rust-lang |
213 | //! [array]: prim@array |
214 | //! [slice]: prim@slice |
215 | // To run std tests without x.py without ending up with two copies of std, Miri needs to be |
216 | // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>. |
217 | // rustc itself never sets the feature, so this line has no effect there. |
218 | #![cfg (any(not(feature = "miri-test-libstd" ), test, doctest))] |
219 | // miri-test-libstd also prefers to make std use the sysroot versions of the dependencies. |
220 | #![cfg_attr (feature = "miri-test-libstd" , feature(rustc_private))] |
221 | // |
222 | #![cfg_attr (not(feature = "restricted-std" ), stable(feature = "rust1" , since = "1.0.0" ))] |
223 | #![cfg_attr (feature = "restricted-std" , unstable(feature = "restricted_std" , issue = "none" ))] |
224 | #![doc ( |
225 | html_playground_url = "https://play.rust-lang.org/" , |
226 | issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/" , |
227 | test(no_crate_inject, attr(deny(warnings))), |
228 | test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) |
229 | )] |
230 | #![doc (rust_logo)] |
231 | #![doc (cfg_hide( |
232 | not(test), |
233 | not(any(test, bootstrap)), |
234 | no_global_oom_handling, |
235 | not(no_global_oom_handling) |
236 | ))] |
237 | // Don't link to std. We are std. |
238 | #![no_std ] |
239 | // Tell the compiler to link to either panic_abort or panic_unwind |
240 | #![needs_panic_runtime ] |
241 | // |
242 | // Lints: |
243 | #![warn (deprecated_in_future)] |
244 | #![warn (missing_docs)] |
245 | #![warn (missing_debug_implementations)] |
246 | #![allow (explicit_outlives_requirements)] |
247 | #![allow (unused_lifetimes)] |
248 | #![allow (internal_features)] |
249 | #![deny (rustc::existing_doc_keyword)] |
250 | #![deny (fuzzy_provenance_casts)] |
251 | #![allow (rustdoc::redundant_explicit_links)] |
252 | // Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind` |
253 | #![deny (ffi_unwind_calls)] |
254 | // std may use features in a platform-specific way |
255 | #![allow (unused_features)] |
256 | // |
257 | // Features: |
258 | #![cfg_attr (test, feature(internal_output_capture, print_internals, update_panic_count, rt))] |
259 | #![cfg_attr ( |
260 | all(target_vendor = "fortanix" , target_env = "sgx" ), |
261 | feature(slice_index_methods, coerce_unsized, sgx_platform) |
262 | )] |
263 | #![cfg_attr (any(windows, target_os = "uefi" ), feature(round_char_boundary))] |
264 | #![cfg_attr (target_os = "xous" , feature(slice_ptr_len))] |
265 | // |
266 | // Language features: |
267 | // tidy-alphabetical-start |
268 | #![cfg_attr (not(bootstrap), feature(cfg_sanitizer_cfi))] |
269 | #![feature (alloc_error_handler)] |
270 | #![feature (allocator_internals)] |
271 | #![feature (allow_internal_unsafe)] |
272 | #![feature (allow_internal_unstable)] |
273 | #![feature (c_unwind)] |
274 | #![feature (cfg_target_thread_local)] |
275 | #![feature (cfi_encoding)] |
276 | #![feature (concat_idents)] |
277 | #![feature (const_mut_refs)] |
278 | #![feature (const_trait_impl)] |
279 | #![feature (decl_macro)] |
280 | #![feature (deprecated_suggestion)] |
281 | #![feature (doc_cfg)] |
282 | #![feature (doc_cfg_hide)] |
283 | #![feature (doc_masked)] |
284 | #![feature (doc_notable_trait)] |
285 | #![feature (dropck_eyepatch)] |
286 | #![feature (exhaustive_patterns)] |
287 | #![feature (if_let_guard)] |
288 | #![feature (intra_doc_pointers)] |
289 | #![feature (lang_items)] |
290 | #![feature (let_chains)] |
291 | #![feature (link_cfg)] |
292 | #![feature (linkage)] |
293 | #![feature (min_specialization)] |
294 | #![feature (must_not_suspend)] |
295 | #![feature (needs_panic_runtime)] |
296 | #![feature (negative_impls)] |
297 | #![feature (never_type)] |
298 | #![feature (no_sanitize)] |
299 | #![feature (platform_intrinsics)] |
300 | #![feature (prelude_import)] |
301 | #![feature (rustc_attrs)] |
302 | #![feature (rustdoc_internals)] |
303 | #![feature (staged_api)] |
304 | #![feature (thread_local)] |
305 | #![feature (try_blocks)] |
306 | #![feature (type_alias_impl_trait)] |
307 | #![feature (utf8_chunks)] |
308 | // tidy-alphabetical-end |
309 | // |
310 | // Library features (core): |
311 | // tidy-alphabetical-start |
312 | #![cfg_attr (bootstrap, feature(c_str_literals))] |
313 | #![feature (char_internals)] |
314 | #![feature (core_intrinsics)] |
315 | #![feature (core_io_borrowed_buf)] |
316 | #![feature (duration_constants)] |
317 | #![feature (error_generic_member_access)] |
318 | #![feature (error_in_core)] |
319 | #![feature (error_iter)] |
320 | #![feature (exact_size_is_empty)] |
321 | #![feature (exclusive_wrapper)] |
322 | #![feature (exposed_provenance)] |
323 | #![feature (extend_one)] |
324 | #![feature (float_gamma)] |
325 | #![feature (float_minimum_maximum)] |
326 | #![feature (float_next_up_down)] |
327 | #![feature (generic_nonzero)] |
328 | #![feature (hasher_prefixfree_extras)] |
329 | #![feature (hashmap_internals)] |
330 | #![feature (hint_assert_unchecked)] |
331 | #![feature (ip)] |
332 | #![feature (maybe_uninit_slice)] |
333 | #![feature (maybe_uninit_uninit_array)] |
334 | #![feature (maybe_uninit_write_slice)] |
335 | #![feature (panic_can_unwind)] |
336 | #![feature (panic_info_message)] |
337 | #![feature (panic_internals)] |
338 | #![feature (pointer_is_aligned)] |
339 | #![feature (portable_simd)] |
340 | #![feature (prelude_2024)] |
341 | #![feature (ptr_as_uninit)] |
342 | #![feature (slice_internals)] |
343 | #![feature (slice_ptr_get)] |
344 | #![feature (slice_range)] |
345 | #![feature (std_internals)] |
346 | #![feature (str_internals)] |
347 | #![feature (strict_provenance)] |
348 | // tidy-alphabetical-end |
349 | // |
350 | // Library features (alloc): |
351 | // tidy-alphabetical-start |
352 | #![feature (alloc_layout_extra)] |
353 | #![feature (allocator_api)] |
354 | #![feature (get_mut_unchecked)] |
355 | #![feature (map_try_insert)] |
356 | #![feature (new_uninit)] |
357 | #![feature (slice_concat_trait)] |
358 | #![feature (thin_box)] |
359 | #![feature (try_reserve_kind)] |
360 | #![feature (vec_into_raw_parts)] |
361 | // tidy-alphabetical-end |
362 | // |
363 | // Library features (unwind): |
364 | // tidy-alphabetical-start |
365 | #![feature (panic_unwind)] |
366 | // tidy-alphabetical-end |
367 | // |
368 | // Only for re-exporting: |
369 | // tidy-alphabetical-start |
370 | #![feature (assert_matches)] |
371 | #![feature (async_iterator)] |
372 | #![feature (c_variadic)] |
373 | #![feature (cfg_accessible)] |
374 | #![feature (cfg_eval)] |
375 | #![feature (concat_bytes)] |
376 | #![feature (const_format_args)] |
377 | #![feature (custom_test_frameworks)] |
378 | #![feature (edition_panic)] |
379 | #![feature (format_args_nl)] |
380 | #![feature (get_many_mut)] |
381 | #![feature (lazy_cell)] |
382 | #![feature (log_syntax)] |
383 | #![feature (stdsimd)] |
384 | #![feature (test)] |
385 | #![feature (trace_macros)] |
386 | // tidy-alphabetical-end |
387 | // |
388 | // Only used in tests/benchmarks: |
389 | // |
390 | // Only for const-ness: |
391 | // tidy-alphabetical-start |
392 | #![feature (const_collections_with_hasher)] |
393 | #![feature (const_hash)] |
394 | #![feature (const_io_structs)] |
395 | #![feature (const_ip)] |
396 | #![feature (const_ipv4)] |
397 | #![feature (const_ipv6)] |
398 | #![feature (const_maybe_uninit_uninit_array)] |
399 | #![feature (const_waker)] |
400 | #![feature (thread_local_internals)] |
401 | // tidy-alphabetical-end |
402 | // |
403 | #![default_lib_allocator ] |
404 | |
405 | // Explicitly import the prelude. The compiler uses this same unstable attribute |
406 | // to import the prelude implicitly when building crates that depend on std. |
407 | #[prelude_import ] |
408 | #[allow (unused)] |
409 | use prelude::rust_2021::*; |
410 | |
411 | // Access to Bencher, etc. |
412 | #[cfg (test)] |
413 | extern crate test; |
414 | |
415 | #[allow (unused_imports)] // macros from `alloc` are not used on all platforms |
416 | #[macro_use ] |
417 | extern crate alloc as alloc_crate; |
418 | #[doc (masked)] |
419 | #[allow (unused_extern_crates)] |
420 | extern crate libc; |
421 | |
422 | // We always need an unwinder currently for backtraces |
423 | #[doc (masked)] |
424 | #[allow (unused_extern_crates)] |
425 | extern crate unwind; |
426 | |
427 | // FIXME: #94122 this extern crate definition only exist here to stop |
428 | // miniz_oxide docs leaking into std docs. Find better way to do it. |
429 | // Remove exclusion from tidy platform check when this removed. |
430 | #[doc (masked)] |
431 | #[allow (unused_extern_crates)] |
432 | #[cfg (all( |
433 | not(all(windows, target_env = "msvc" , not(target_vendor = "uwp" ))), |
434 | feature = "miniz_oxide" |
435 | ))] |
436 | extern crate miniz_oxide; |
437 | |
438 | // During testing, this crate is not actually the "real" std library, but rather |
439 | // it links to the real std library, which was compiled from this same source |
440 | // code. So any lang items std defines are conditionally excluded (or else they |
441 | // would generate duplicate lang item errors), and any globals it defines are |
442 | // _not_ the globals used by "real" std. So this import, defined only during |
443 | // testing gives test-std access to real-std lang items and globals. See #2912 |
444 | #[cfg (test)] |
445 | extern crate std as realstd; |
446 | |
447 | // The standard macros that are not built-in to the compiler. |
448 | #[macro_use ] |
449 | mod macros; |
450 | |
451 | // The runtime entry point and a few unstable public functions used by the |
452 | // compiler |
453 | #[macro_use ] |
454 | pub mod rt; |
455 | |
456 | // The Rust prelude |
457 | pub mod prelude; |
458 | |
459 | // Public module declarations and re-exports |
460 | #[stable (feature = "rust1" , since = "1.0.0" )] |
461 | pub use alloc_crate::borrow; |
462 | #[stable (feature = "rust1" , since = "1.0.0" )] |
463 | pub use alloc_crate::boxed; |
464 | #[stable (feature = "rust1" , since = "1.0.0" )] |
465 | pub use alloc_crate::fmt; |
466 | #[stable (feature = "rust1" , since = "1.0.0" )] |
467 | pub use alloc_crate::format; |
468 | #[stable (feature = "rust1" , since = "1.0.0" )] |
469 | pub use alloc_crate::rc; |
470 | #[stable (feature = "rust1" , since = "1.0.0" )] |
471 | pub use alloc_crate::slice; |
472 | #[stable (feature = "rust1" , since = "1.0.0" )] |
473 | pub use alloc_crate::str; |
474 | #[stable (feature = "rust1" , since = "1.0.0" )] |
475 | pub use alloc_crate::string; |
476 | #[stable (feature = "rust1" , since = "1.0.0" )] |
477 | pub use alloc_crate::vec; |
478 | #[stable (feature = "rust1" , since = "1.0.0" )] |
479 | pub use core::any; |
480 | #[stable (feature = "core_array" , since = "1.36.0" )] |
481 | pub use core::array; |
482 | #[unstable (feature = "async_iterator" , issue = "79024" )] |
483 | pub use core::async_iter; |
484 | #[stable (feature = "rust1" , since = "1.0.0" )] |
485 | pub use core::cell; |
486 | #[stable (feature = "rust1" , since = "1.0.0" )] |
487 | pub use core::char; |
488 | #[stable (feature = "rust1" , since = "1.0.0" )] |
489 | pub use core::clone; |
490 | #[stable (feature = "rust1" , since = "1.0.0" )] |
491 | pub use core::cmp; |
492 | #[stable (feature = "rust1" , since = "1.0.0" )] |
493 | pub use core::convert; |
494 | #[stable (feature = "rust1" , since = "1.0.0" )] |
495 | pub use core::default; |
496 | #[stable (feature = "futures_api" , since = "1.36.0" )] |
497 | pub use core::future; |
498 | #[stable (feature = "core_hint" , since = "1.27.0" )] |
499 | pub use core::hint; |
500 | #[stable (feature = "i128" , since = "1.26.0" )] |
501 | #[allow (deprecated, deprecated_in_future)] |
502 | pub use core::i128; |
503 | #[stable (feature = "rust1" , since = "1.0.0" )] |
504 | #[allow (deprecated, deprecated_in_future)] |
505 | pub use core::i16; |
506 | #[stable (feature = "rust1" , since = "1.0.0" )] |
507 | #[allow (deprecated, deprecated_in_future)] |
508 | pub use core::i32; |
509 | #[stable (feature = "rust1" , since = "1.0.0" )] |
510 | #[allow (deprecated, deprecated_in_future)] |
511 | pub use core::i64; |
512 | #[stable (feature = "rust1" , since = "1.0.0" )] |
513 | #[allow (deprecated, deprecated_in_future)] |
514 | pub use core::i8; |
515 | #[stable (feature = "rust1" , since = "1.0.0" )] |
516 | pub use core::intrinsics; |
517 | #[stable (feature = "rust1" , since = "1.0.0" )] |
518 | #[allow (deprecated, deprecated_in_future)] |
519 | pub use core::isize; |
520 | #[stable (feature = "rust1" , since = "1.0.0" )] |
521 | pub use core::iter; |
522 | #[stable (feature = "rust1" , since = "1.0.0" )] |
523 | pub use core::marker; |
524 | #[stable (feature = "rust1" , since = "1.0.0" )] |
525 | pub use core::mem; |
526 | #[stable (feature = "rust1" , since = "1.0.0" )] |
527 | pub use core::ops; |
528 | #[stable (feature = "rust1" , since = "1.0.0" )] |
529 | pub use core::option; |
530 | #[stable (feature = "pin" , since = "1.33.0" )] |
531 | pub use core::pin; |
532 | #[stable (feature = "rust1" , since = "1.0.0" )] |
533 | pub use core::ptr; |
534 | #[stable (feature = "rust1" , since = "1.0.0" )] |
535 | pub use core::result; |
536 | #[stable (feature = "i128" , since = "1.26.0" )] |
537 | #[allow (deprecated, deprecated_in_future)] |
538 | pub use core::u128; |
539 | #[stable (feature = "rust1" , since = "1.0.0" )] |
540 | #[allow (deprecated, deprecated_in_future)] |
541 | pub use core::u16; |
542 | #[stable (feature = "rust1" , since = "1.0.0" )] |
543 | #[allow (deprecated, deprecated_in_future)] |
544 | pub use core::u32; |
545 | #[stable (feature = "rust1" , since = "1.0.0" )] |
546 | #[allow (deprecated, deprecated_in_future)] |
547 | pub use core::u64; |
548 | #[stable (feature = "rust1" , since = "1.0.0" )] |
549 | #[allow (deprecated, deprecated_in_future)] |
550 | pub use core::u8; |
551 | #[stable (feature = "rust1" , since = "1.0.0" )] |
552 | #[allow (deprecated, deprecated_in_future)] |
553 | pub use core::usize; |
554 | |
555 | pub mod f32; |
556 | pub mod f64; |
557 | |
558 | #[macro_use ] |
559 | pub mod thread; |
560 | pub mod ascii; |
561 | pub mod backtrace; |
562 | pub mod collections; |
563 | pub mod env; |
564 | pub mod error; |
565 | pub mod ffi; |
566 | pub mod fs; |
567 | pub mod hash; |
568 | pub mod io; |
569 | pub mod net; |
570 | pub mod num; |
571 | pub mod os; |
572 | pub mod panic; |
573 | pub mod path; |
574 | pub mod process; |
575 | pub mod sync; |
576 | pub mod time; |
577 | |
578 | // Pull in `std_float` crate into std. The contents of |
579 | // `std_float` are in a different repository: rust-lang/portable-simd. |
580 | #[path = "../../portable-simd/crates/std_float/src/lib.rs" ] |
581 | #[allow (missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)] |
582 | #[allow (rustdoc::bare_urls)] |
583 | #[unstable (feature = "portable_simd" , issue = "86656" )] |
584 | mod std_float; |
585 | |
586 | #[unstable (feature = "portable_simd" , issue = "86656" )] |
587 | pub mod simd { |
588 | #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md" )] |
589 | |
590 | #[doc (inline)] |
591 | pub use crate::std_float::StdFloat; |
592 | #[doc (inline)] |
593 | pub use core::simd::*; |
594 | } |
595 | |
596 | #[stable (feature = "futures_api" , since = "1.36.0" )] |
597 | pub mod task { |
598 | //! Types and Traits for working with asynchronous tasks. |
599 | |
600 | #[doc (inline)] |
601 | #[stable (feature = "futures_api" , since = "1.36.0" )] |
602 | pub use core::task::*; |
603 | |
604 | #[doc (inline)] |
605 | #[stable (feature = "wake_trait" , since = "1.51.0" )] |
606 | pub use alloc::task::*; |
607 | } |
608 | |
609 | #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md" )] |
610 | #[stable (feature = "simd_arch" , since = "1.27.0" )] |
611 | pub mod arch { |
612 | #[stable (feature = "simd_arch" , since = "1.27.0" )] |
613 | // The `no_inline`-attribute is required to make the documentation of all |
614 | // targets available. |
615 | // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for |
616 | // more information. |
617 | #[doc (no_inline)] // Note (#82861): required for correct documentation |
618 | pub use core::arch::*; |
619 | |
620 | #[stable (feature = "simd_aarch64" , since = "1.60.0" )] |
621 | pub use std_detect::is_aarch64_feature_detected; |
622 | #[stable (feature = "simd_x86" , since = "1.27.0" )] |
623 | pub use std_detect::is_x86_feature_detected; |
624 | #[unstable (feature = "stdsimd" , issue = "48556" )] |
625 | pub use std_detect::{ |
626 | is_arm_feature_detected, is_mips64_feature_detected, is_mips_feature_detected, |
627 | is_powerpc64_feature_detected, is_powerpc_feature_detected, is_riscv_feature_detected, |
628 | }; |
629 | } |
630 | |
631 | // This was stabilized in the crate root so we have to keep it there. |
632 | #[stable (feature = "simd_x86" , since = "1.27.0" )] |
633 | pub use std_detect::is_x86_feature_detected; |
634 | |
635 | // Platform-abstraction modules |
636 | mod sys; |
637 | mod sys_common; |
638 | |
639 | pub mod alloc; |
640 | |
641 | // Private support modules |
642 | mod panicking; |
643 | |
644 | #[path = "../../backtrace/src/lib.rs" ] |
645 | #[allow (dead_code, unused_attributes, fuzzy_provenance_casts)] |
646 | mod backtrace_rs; |
647 | |
648 | // Re-export macros defined in core. |
649 | #[stable (feature = "rust1" , since = "1.0.0" )] |
650 | #[allow (deprecated, deprecated_in_future)] |
651 | pub use core::{ |
652 | assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, todo, r#try, |
653 | unimplemented, unreachable, write, writeln, |
654 | }; |
655 | |
656 | // Re-export built-in macros defined through core. |
657 | #[stable (feature = "builtin_macro_prelude" , since = "1.38.0" )] |
658 | #[allow (deprecated)] |
659 | pub use core::{ |
660 | assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args, |
661 | env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, |
662 | module_path, option_env, stringify, trace_macros, |
663 | }; |
664 | |
665 | #[unstable ( |
666 | feature = "concat_bytes" , |
667 | issue = "87555" , |
668 | reason = "`concat_bytes` is not stable enough for use and is subject to change" |
669 | )] |
670 | pub use core::concat_bytes; |
671 | |
672 | #[unstable (feature = "cfg_match" , issue = "115585" )] |
673 | pub use core::cfg_match; |
674 | |
675 | #[stable (feature = "core_primitive" , since = "1.43.0" )] |
676 | pub use core::primitive; |
677 | |
678 | // Include a number of private modules that exist solely to provide |
679 | // the rustdoc documentation for primitive types. Using `include!` |
680 | // because rustdoc only looks for these modules at the crate level. |
681 | include!("../../core/src/primitive_docs.rs" ); |
682 | |
683 | // Include a number of private modules that exist solely to provide |
684 | // the rustdoc documentation for the existing keywords. Using `include!` |
685 | // because rustdoc only looks for these modules at the crate level. |
686 | include!("keyword_docs.rs" ); |
687 | |
688 | // This is required to avoid an unstable error when `restricted-std` is not |
689 | // enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std |
690 | // is unconditional, so the unstable feature needs to be defined somewhere. |
691 | #[unstable (feature = "restricted_std" , issue = "none" )] |
692 | mod __restricted_std_workaround {} |
693 | |
694 | mod sealed { |
695 | /// This trait being unreachable from outside the crate |
696 | /// prevents outside implementations of our extension traits. |
697 | /// This allows adding more trait methods in the future. |
698 | #[unstable (feature = "sealed" , issue = "none" )] |
699 | pub trait Sealed {} |
700 | } |
701 | |
702 | #[cfg (test)] |
703 | #[allow (dead_code)] // Not used in all configurations. |
704 | pub(crate) mod test_helpers { |
705 | /// Test-only replacement for `rand::thread_rng()`, which is unusable for |
706 | /// us, as we want to allow running stdlib tests on tier-3 targets which may |
707 | /// not have `getrandom` support. |
708 | /// |
709 | /// Does a bit of a song and dance to ensure that the seed is different on |
710 | /// each call (as some tests sadly rely on this), but doesn't try that hard. |
711 | /// |
712 | /// This is duplicated in the `core`, `alloc` test suites (as well as |
713 | /// `std`'s integration tests), but figuring out a mechanism to share these |
714 | /// seems far more painful than copy-pasting a 7 line function a couple |
715 | /// times, given that even under a perma-unstable feature, I don't think we |
716 | /// want to expose types from `rand` from `std`. |
717 | #[track_caller ] |
718 | pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng { |
719 | use core::hash::{BuildHasher, Hash, Hasher}; |
720 | let mut hasher = crate::hash::RandomState::new().build_hasher(); |
721 | core::panic::Location::caller().hash(&mut hasher); |
722 | let hc64 = hasher.finish(); |
723 | let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>(); |
724 | let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); |
725 | rand::SeedableRng::from_seed(seed) |
726 | } |
727 | } |
728 | |