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