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 //! [I/O]: io 156 //! [`MIN`]: i32::MIN 157 //! [`MAX`]: i32::MAX 158 //! [page for the module `std::i32`]: crate::i32 159 //! [TCP]: net::TcpStream 160 //! [The Rust Prelude]: prelude 161 //! [UDP]: net::UdpSocket 162 //! [`Arc`]: sync::Arc 163 //! [owned slice]: boxed 164 //! [`Cell`]: cell::Cell 165 //! [`FromStr`]: str::FromStr 166 //! [`HashMap<K, V>`]: collections::HashMap 167 //! [`Mutex`]: sync::Mutex 168 //! [`Option<T>`]: option::Option 169 //! [`Rc`]: rc::Rc 170 //! [`RefCell`]: cell::RefCell 171 //! [`Result<T, E>`]: result::Result 172 //! [`Vec<T>`]: vec::Vec 173 //! [`atomic`]: sync::atomic 174 //! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for 175 //! [`str`]: prim@str 176 //! [`mpsc`]: sync::mpsc 177 //! [`std::cmp`]: cmp 178 //! [`std::slice`]: mod@slice 179 //! [`use std::env`]: env/index.html 180 //! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html 181 //! [crates.io]: https://crates.io 182 //! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods 183 //! [files]: fs::File 184 //! [multithreading]: thread 185 //! [other]: #what-is-in-the-standard-library-documentation 186 //! [primitive types]: ../book/ch03-02-data-types.html 187 //! [rust-discord]: https://discord.gg/rust-lang 188 //! [array]: prim@array 189 //! [slice]: prim@slice 190 191 // To run std tests without x.py without ending up with two copies of std, Miri needs to be 192 // able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>. 193 // rustc itself never sets the feature, so this line has no affect there. 194 #![cfg(any(not(feature = "miri-test-libstd"), test, doctest))] 195 // miri-test-libstd also prefers to make std use the sysroot versions of the dependencies. 196 #![cfg_attr(feature = "miri-test-libstd", feature(rustc_private))] 197 // 198 #![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))] 199 #![cfg_attr(feature = "restricted-std", unstable(feature = "restricted_std", issue = "none"))] 200 #![doc( 201 html_playground_url = "https://play.rust-lang.org/", 202 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/", 203 test(no_crate_inject, attr(deny(warnings))), 204 test(attr(allow(dead_code, deprecated, unused_variables, unused_mut))) 205 )] 206 #![doc(cfg_hide( 207 not(test), 208 not(any(test, bootstrap)), 209 no_global_oom_handling, 210 not(no_global_oom_handling) 211 ))] 212 // Don't link to std. We are std. 213 #![no_std] 214 // Tell the compiler to link to either panic_abort or panic_unwind 215 #![needs_panic_runtime] 216 // 217 // Lints: 218 #![warn(deprecated_in_future)] 219 #![warn(missing_docs)] 220 #![warn(missing_debug_implementations)] 221 #![allow(explicit_outlives_requirements)] 222 #![allow(unused_lifetimes)] 223 #![deny(rustc::existing_doc_keyword)] 224 #![deny(fuzzy_provenance_casts)] 225 // Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind` 226 #![deny(ffi_unwind_calls)] 227 // std may use features in a platform-specific way 228 #![allow(unused_features)] 229 // 230 // Features: 231 #![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))] 232 #![cfg_attr( 233 all(target_vendor = "fortanix", target_env = "sgx"), 234 feature(slice_index_methods, coerce_unsized, sgx_platform) 235 )] 236 #![cfg_attr(windows, feature(round_char_boundary))] 237 // 238 // Language features: 239 // tidy-alphabetical-start 240 #![feature(alloc_error_handler)] 241 #![feature(allocator_internals)] 242 #![feature(allow_internal_unsafe)] 243 #![feature(allow_internal_unstable)] 244 #![feature(c_unwind)] 245 #![feature(cfg_target_thread_local)] 246 #![feature(concat_idents)] 247 #![feature(const_mut_refs)] 248 #![feature(const_trait_impl)] 249 #![feature(decl_macro)] 250 #![feature(deprecated_suggestion)] 251 #![feature(doc_cfg)] 252 #![feature(doc_cfg_hide)] 253 #![feature(doc_masked)] 254 #![feature(doc_notable_trait)] 255 #![feature(dropck_eyepatch)] 256 #![feature(exhaustive_patterns)] 257 #![feature(if_let_guard)] 258 #![feature(intra_doc_pointers)] 259 #![feature(lang_items)] 260 #![feature(let_chains)] 261 #![feature(link_cfg)] 262 #![feature(linkage)] 263 #![feature(min_specialization)] 264 #![feature(must_not_suspend)] 265 #![feature(needs_panic_runtime)] 266 #![feature(negative_impls)] 267 #![feature(never_type)] 268 #![feature(platform_intrinsics)] 269 #![feature(prelude_import)] 270 #![feature(rustc_attrs)] 271 #![feature(rustdoc_internals)] 272 #![feature(staged_api)] 273 #![feature(thread_local)] 274 #![feature(try_blocks)] 275 #![feature(utf8_chunks)] 276 // tidy-alphabetical-end 277 // 278 // Library features (core): 279 // tidy-alphabetical-start 280 #![feature(char_internals)] 281 #![feature(core_intrinsics)] 282 #![feature(duration_constants)] 283 #![feature(error_generic_member_access)] 284 #![feature(error_in_core)] 285 #![feature(error_iter)] 286 #![feature(exact_size_is_empty)] 287 #![feature(exclusive_wrapper)] 288 #![feature(extend_one)] 289 #![feature(float_minimum_maximum)] 290 #![feature(float_next_up_down)] 291 #![feature(hasher_prefixfree_extras)] 292 #![feature(hashmap_internals)] 293 #![feature(int_roundings)] 294 #![feature(ip)] 295 #![feature(ip_in_core)] 296 #![feature(maybe_uninit_slice)] 297 #![feature(maybe_uninit_uninit_array)] 298 #![feature(maybe_uninit_write_slice)] 299 #![feature(panic_can_unwind)] 300 #![feature(panic_info_message)] 301 #![feature(panic_internals)] 302 #![feature(pointer_byte_offsets)] 303 #![feature(pointer_is_aligned)] 304 #![feature(portable_simd)] 305 #![feature(prelude_2024)] 306 #![feature(provide_any)] 307 #![feature(ptr_as_uninit)] 308 #![feature(raw_os_nonzero)] 309 #![feature(round_ties_even)] 310 #![feature(slice_internals)] 311 #![feature(slice_ptr_get)] 312 #![feature(std_internals)] 313 #![feature(str_internals)] 314 #![feature(strict_provenance)] 315 // tidy-alphabetical-end 316 // 317 // Library features (alloc): 318 // tidy-alphabetical-start 319 #![feature(alloc_layout_extra)] 320 #![feature(allocator_api)] 321 #![feature(get_mut_unchecked)] 322 #![feature(map_try_insert)] 323 #![feature(new_uninit)] 324 #![feature(slice_concat_trait)] 325 #![feature(thin_box)] 326 #![feature(try_reserve_kind)] 327 #![feature(vec_into_raw_parts)] 328 // tidy-alphabetical-end 329 // 330 // Library features (unwind): 331 // tidy-alphabetical-start 332 #![feature(panic_unwind)] 333 // tidy-alphabetical-end 334 // 335 // Only for re-exporting: 336 // tidy-alphabetical-start 337 #![feature(assert_matches)] 338 #![feature(async_iterator)] 339 #![feature(c_variadic)] 340 #![feature(cfg_accessible)] 341 #![feature(cfg_eval)] 342 #![feature(concat_bytes)] 343 #![feature(const_format_args)] 344 #![feature(core_panic)] 345 #![feature(custom_test_frameworks)] 346 #![feature(edition_panic)] 347 #![feature(format_args_nl)] 348 #![feature(get_many_mut)] 349 #![feature(lazy_cell)] 350 #![feature(log_syntax)] 351 #![feature(saturating_int_impl)] 352 #![feature(stdsimd)] 353 #![feature(test)] 354 #![feature(trace_macros)] 355 // tidy-alphabetical-end 356 // 357 // Only used in tests/benchmarks: 358 // 359 // Only for const-ness: 360 // tidy-alphabetical-start 361 #![feature(const_collections_with_hasher)] 362 #![feature(const_hash)] 363 #![feature(const_io_structs)] 364 #![feature(const_ip)] 365 #![feature(const_ipv4)] 366 #![feature(const_ipv6)] 367 #![feature(const_maybe_uninit_uninit_array)] 368 #![feature(const_waker)] 369 #![feature(thread_local_internals)] 370 // tidy-alphabetical-end 371 // 372 #![default_lib_allocator] 373 374 // Explicitly import the prelude. The compiler uses this same unstable attribute 375 // to import the prelude implicitly when building crates that depend on std. 376 #[prelude_import] 377 #[allow(unused)] 378 use prelude::rust_2021::*; 379 380 // Access to Bencher, etc. 381 #[cfg(test)] 382 extern crate test; 383 384 #[allow(unused_imports)] // macros from `alloc` are not used on all platforms 385 #[macro_use] 386 extern crate alloc as alloc_crate; 387 #[doc(masked)] 388 #[allow(unused_extern_crates)] 389 extern crate libc; 390 391 // We always need an unwinder currently for backtraces 392 #[doc(masked)] 393 #[allow(unused_extern_crates)] 394 extern crate unwind; 395 396 #[doc(masked)] 397 #[allow(unused_extern_crates)] 398 #[cfg(feature = "miniz_oxide")] 399 extern crate miniz_oxide; 400 401 // During testing, this crate is not actually the "real" std library, but rather 402 // it links to the real std library, which was compiled from this same source 403 // code. So any lang items std defines are conditionally excluded (or else they 404 // would generate duplicate lang item errors), and any globals it defines are 405 // _not_ the globals used by "real" std. So this import, defined only during 406 // testing gives test-std access to real-std lang items and globals. See #2912 407 #[cfg(test)] 408 extern crate std as realstd; 409 410 // The standard macros that are not built-in to the compiler. 411 #[macro_use] 412 mod macros; 413 414 // The runtime entry point and a few unstable public functions used by the 415 // compiler 416 #[macro_use] 417 pub mod rt; 418 419 // The Rust prelude 420 pub mod prelude; 421 422 // Public module declarations and re-exports 423 #[stable(feature = "rust1", since = "1.0.0")] 424 pub use alloc_crate::borrow; 425 #[stable(feature = "rust1", since = "1.0.0")] 426 pub use alloc_crate::boxed; 427 #[stable(feature = "rust1", since = "1.0.0")] 428 pub use alloc_crate::fmt; 429 #[stable(feature = "rust1", since = "1.0.0")] 430 pub use alloc_crate::format; 431 #[stable(feature = "rust1", since = "1.0.0")] 432 pub use alloc_crate::rc; 433 #[stable(feature = "rust1", since = "1.0.0")] 434 pub use alloc_crate::slice; 435 #[stable(feature = "rust1", since = "1.0.0")] 436 pub use alloc_crate::str; 437 #[stable(feature = "rust1", since = "1.0.0")] 438 pub use alloc_crate::string; 439 #[stable(feature = "rust1", since = "1.0.0")] 440 pub use alloc_crate::vec; 441 #[stable(feature = "rust1", since = "1.0.0")] 442 pub use core::any; 443 #[stable(feature = "core_array", since = "1.36.0")] 444 pub use core::array; 445 #[unstable(feature = "async_iterator", issue = "79024")] 446 pub use core::async_iter; 447 #[stable(feature = "rust1", since = "1.0.0")] 448 pub use core::cell; 449 #[stable(feature = "rust1", since = "1.0.0")] 450 pub use core::char; 451 #[stable(feature = "rust1", since = "1.0.0")] 452 pub use core::clone; 453 #[stable(feature = "rust1", since = "1.0.0")] 454 pub use core::cmp; 455 #[stable(feature = "rust1", since = "1.0.0")] 456 pub use core::convert; 457 #[stable(feature = "rust1", since = "1.0.0")] 458 pub use core::default; 459 #[stable(feature = "futures_api", since = "1.36.0")] 460 pub use core::future; 461 #[stable(feature = "rust1", since = "1.0.0")] 462 pub use core::hash; 463 #[stable(feature = "core_hint", since = "1.27.0")] 464 pub use core::hint; 465 #[stable(feature = "i128", since = "1.26.0")] 466 #[allow(deprecated, deprecated_in_future)] 467 pub use core::i128; 468 #[stable(feature = "rust1", since = "1.0.0")] 469 #[allow(deprecated, deprecated_in_future)] 470 pub use core::i16; 471 #[stable(feature = "rust1", since = "1.0.0")] 472 #[allow(deprecated, deprecated_in_future)] 473 pub use core::i32; 474 #[stable(feature = "rust1", since = "1.0.0")] 475 #[allow(deprecated, deprecated_in_future)] 476 pub use core::i64; 477 #[stable(feature = "rust1", since = "1.0.0")] 478 #[allow(deprecated, deprecated_in_future)] 479 pub use core::i8; 480 #[stable(feature = "rust1", since = "1.0.0")] 481 pub use core::intrinsics; 482 #[stable(feature = "rust1", since = "1.0.0")] 483 #[allow(deprecated, deprecated_in_future)] 484 pub use core::isize; 485 #[stable(feature = "rust1", since = "1.0.0")] 486 pub use core::iter; 487 #[stable(feature = "rust1", since = "1.0.0")] 488 pub use core::marker; 489 #[stable(feature = "rust1", since = "1.0.0")] 490 pub use core::mem; 491 #[stable(feature = "rust1", since = "1.0.0")] 492 pub use core::ops; 493 #[stable(feature = "rust1", since = "1.0.0")] 494 pub use core::option; 495 #[stable(feature = "pin", since = "1.33.0")] 496 pub use core::pin; 497 #[stable(feature = "rust1", since = "1.0.0")] 498 pub use core::ptr; 499 #[stable(feature = "rust1", since = "1.0.0")] 500 pub use core::result; 501 #[stable(feature = "i128", since = "1.26.0")] 502 #[allow(deprecated, deprecated_in_future)] 503 pub use core::u128; 504 #[stable(feature = "rust1", since = "1.0.0")] 505 #[allow(deprecated, deprecated_in_future)] 506 pub use core::u16; 507 #[stable(feature = "rust1", since = "1.0.0")] 508 #[allow(deprecated, deprecated_in_future)] 509 pub use core::u32; 510 #[stable(feature = "rust1", since = "1.0.0")] 511 #[allow(deprecated, deprecated_in_future)] 512 pub use core::u64; 513 #[stable(feature = "rust1", since = "1.0.0")] 514 #[allow(deprecated, deprecated_in_future)] 515 pub use core::u8; 516 #[stable(feature = "rust1", since = "1.0.0")] 517 #[allow(deprecated, deprecated_in_future)] 518 pub use core::usize; 519 520 pub mod f32; 521 pub mod f64; 522 523 #[macro_use] 524 pub mod thread; 525 pub mod ascii; 526 pub mod backtrace; 527 pub mod collections; 528 pub mod env; 529 pub mod error; 530 pub mod ffi; 531 pub mod fs; 532 pub mod io; 533 pub mod net; 534 pub mod num; 535 pub mod os; 536 pub mod panic; 537 pub mod path; 538 pub mod process; 539 pub mod sync; 540 pub mod time; 541 542 // Pull in `std_float` crate into std. The contents of 543 // `std_float` are in a different repository: rust-lang/portable-simd. 544 #[path = "../../portable-simd/crates/std_float/src/lib.rs"] 545 #[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn, unused_unsafe)] 546 #[allow(rustdoc::bare_urls)] 547 #[unstable(feature = "portable_simd", issue = "86656")] 548 mod std_float; 549 550 #[doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")] 551 #[unstable(feature = "portable_simd", issue = "86656")] 552 pub mod simd { 553 #[doc(inline)] 554 pub use crate::std_float::StdFloat; 555 #[doc(inline)] 556 pub use core::simd::*; 557 } 558 559 #[stable(feature = "futures_api", since = "1.36.0")] 560 pub mod task { 561 //! Types and Traits for working with asynchronous tasks. 562 563 #[doc(inline)] 564 #[stable(feature = "futures_api", since = "1.36.0")] 565 pub use core::task::*; 566 567 #[doc(inline)] 568 #[stable(feature = "wake_trait", since = "1.51.0")] 569 pub use alloc::task::*; 570 } 571 572 #[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")] 573 #[stable(feature = "simd_arch", since = "1.27.0")] 574 pub mod arch { 575 #[stable(feature = "simd_arch", since = "1.27.0")] 576 // The `no_inline`-attribute is required to make the documentation of all 577 // targets available. 578 // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for 579 // more information. 580 #[doc(no_inline)] // Note (#82861): required for correct documentation 581 pub use core::arch::*; 582 583 #[stable(feature = "simd_aarch64", since = "1.60.0")] 584 pub use std_detect::is_aarch64_feature_detected; 585 #[stable(feature = "simd_x86", since = "1.27.0")] 586 pub use std_detect::is_x86_feature_detected; 587 #[unstable(feature = "stdsimd", issue = "48556")] 588 pub use std_detect::{ 589 is_arm_feature_detected, is_mips64_feature_detected, is_mips_feature_detected, 590 is_powerpc64_feature_detected, is_powerpc_feature_detected, is_riscv_feature_detected, 591 }; 592 } 593 594 // This was stabilized in the crate root so we have to keep it there. 595 #[stable(feature = "simd_x86", since = "1.27.0")] 596 pub use std_detect::is_x86_feature_detected; 597 598 // Platform-abstraction modules 599 mod sys; 600 mod sys_common; 601 602 pub mod alloc; 603 604 // Private support modules 605 mod panicking; 606 mod personality; 607 608 #[path = "../../backtrace/src/lib.rs"] 609 #[allow(dead_code, unused_attributes, fuzzy_provenance_casts)] 610 mod backtrace_rs; 611 612 // Re-export macros defined in core. 613 #[stable(feature = "rust1", since = "1.0.0")] 614 #[allow(deprecated, deprecated_in_future)] 615 pub use core::{ 616 assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, todo, r#try, 617 unimplemented, unreachable, write, writeln, 618 }; 619 620 // Re-export built-in macros defined through core. 621 #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] 622 #[allow(deprecated)] 623 pub use core::{ 624 assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args, 625 env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax, 626 module_path, option_env, stringify, trace_macros, 627 }; 628 629 #[unstable( 630 feature = "concat_bytes", 631 issue = "87555", 632 reason = "`concat_bytes` is not stable enough for use and is subject to change" 633 )] 634 pub use core::concat_bytes; 635 636 #[stable(feature = "core_primitive", since = "1.43.0")] 637 pub use core::primitive; 638 639 // Include a number of private modules that exist solely to provide 640 // the rustdoc documentation for primitive types. Using `include!` 641 // because rustdoc only looks for these modules at the crate level. 642 include!("primitive_docs.rs"); 643 644 // Include a number of private modules that exist solely to provide 645 // the rustdoc documentation for the existing keywords. Using `include!` 646 // because rustdoc only looks for these modules at the crate level. 647 include!("keyword_docs.rs"); 648 649 // This is required to avoid an unstable error when `restricted-std` is not 650 // enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std 651 // is unconditional, so the unstable feature needs to be defined somewhere. 652 #[unstable(feature = "restricted_std", issue = "none")] 653 mod __restricted_std_workaround {} 654 655 mod sealed { 656 /// This trait being unreachable from outside the crate 657 /// prevents outside implementations of our extension traits. 658 /// This allows adding more trait methods in the future. 659 #[unstable(feature = "sealed", issue = "none")] 660 pub trait Sealed {} 661 } 662 663 #[cfg(test)] 664 #[allow(dead_code)] // Not used in all configurations. 665 pub(crate) mod test_helpers { 666 /// Test-only replacement for `rand::thread_rng()`, which is unusable for 667 /// us, as we want to allow running stdlib tests on tier-3 targets which may 668 /// not have `getrandom` support. 669 /// 670 /// Does a bit of a song and dance to ensure that the seed is different on 671 /// each call (as some tests sadly rely on this), but doesn't try that hard. 672 /// 673 /// This is duplicated in the `core`, `alloc` test suites (as well as 674 /// `std`'s integration tests), but figuring out a mechanism to share these 675 /// seems far more painful than copy-pasting a 7 line function a couple 676 /// times, given that even under a perma-unstable feature, I don't think we 677 /// want to expose types from `rand` from `std`. 678 #[track_caller] test_rng() -> rand_xorshift::XorShiftRng679 pub(crate) fn test_rng() -> rand_xorshift::XorShiftRng { 680 use core::hash::{BuildHasher, Hash, Hasher}; 681 let mut hasher = crate::collections::hash_map::RandomState::new().build_hasher(); 682 core::panic::Location::caller().hash(&mut hasher); 683 let hc64 = hasher.finish(); 684 let seed_vec = hc64.to_le_bytes().into_iter().chain(0u8..8).collect::<Vec<u8>>(); 685 let seed: [u8; 16] = seed_vec.as_slice().try_into().unwrap(); 686 rand::SeedableRng::from_seed(seed) 687 } 688 } 689