]> git.proxmox.com Git - rustc.git/blame - library/std/src/lib.rs
New upstream version 1.52.0+dfsg1
[rustc.git] / library / std / src / lib.rs
CommitLineData
1a4d82fc
JJ
1//! # The Rust Standard Library
2//!
92a42be0
SL
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//!
9fa01778 10//! `std` is available to all Rust crates by default. Therefore, the
92a42be0 11//! standard library can be accessed in [`use`] statements through the path
9fa01778 12//! `std`, as in [`use std::env`].
1a4d82fc 13//!
c1a9b12d 14//! # How to read this documentation
1a4d82fc 15//!
9cc50fc6 16//! If you already know the name of what you are looking for, the fastest way to
92a42be0
SL
17//! find it is to use the <a href="#" onclick="focusSearchBar();">search
18//! bar</a> at the top of the page.
1a4d82fc 19//!
c1a9b12d
SL
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)
3dfed10e 25//! * [The Rust Prelude]
c1a9b12d 26//!
92a42be0
SL
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!
c1a9b12d 32//!
92a42be0
SL
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
83c7162d 35//! development you may want to press the `[-]` button near the top of the
92a42be0 36//! page to collapse it into a more skimmable view.
c1a9b12d 37//!
83c7162d 38//! While you are looking at that `[-]` button also notice the `[src]`
92a42be0
SL
39//! button. 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.
c1a9b12d
SL
42//!
43//! # What is in the standard library documentation?
44//!
92a42be0
SL
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.
c1a9b12d 51//!
92a42be0 52//! Second, implicit methods on [primitive types] are documented here. This can
c1a9b12d
SL
53//! be a source of confusion for two reasons:
54//!
92a42be0
SL
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.
c1a9b12d
SL
62//!
63//! So for example there is a [page for the primitive type
6a06907d 64//! `i32`](primitive::i32) that lists all the methods that can be called on
92a42be0 65//! 32-bit integers (very useful), and there is a [page for the module
3dfed10e
XL
66//! `std::i32`] that documents the constant values [`MIN`] and [`MAX`] (rarely
67//! useful).
92a42be0 68//!
6a06907d 69//! Note the documentation for the primitives [`str`] and [`[T]`][prim@slice] (also
92a42be0 70//! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually
6a06907d 71//! calls to methods on [`str`] and [`[T]`][prim@slice] respectively, via [deref
3b2f2976 72//! coercions][deref-coercions].
92a42be0
SL
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
c1a9b12d
SL
77//! documentation a good entry point to learning about the library.
78//!
92a42be0
SL
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.
c1a9b12d 84//!
cc61c64b
XL
85//! # Contributing changes to the documentation
86//!
87//! Check out the rust contribution guidelines [here](
29967ef6 88//! https://rustc-dev-guide.rust-lang.org/contributing.html#writing-documentation).
3dfed10e
XL
89//! The source for this documentation can be found on
90//! [GitHub](https://github.com/rust-lang/rust).
cc61c64b
XL
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
ba9703b0
XL
95//! improved, submit a PR, or chat with us first on [Discord][rust-discord]
96//! #docs.
cc61c64b 97//!
c1a9b12d
SL
98//! # A Tour of The Rust Standard Library
99//!
92a42be0
SL
100//! The rest of this crate documentation is dedicated to pointing out notable
101//! features of The Rust Standard Library.
1a4d82fc 102//!
bd371182 103//! ## Containers and collections
1a4d82fc 104//!
92a42be0
SL
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.
1a4d82fc 109//!
92a42be0 110//! The standard library exposes three common ways to deal with contiguous
c1a9b12d
SL
111//! regions of memory:
112//!
92a42be0 113//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime.
6a06907d
XL
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
92a42be0 116//! storage, whether heap-allocated or not.
c1a9b12d 117//!
92a42be0
SL
118//! Slices can only be handled through some kind of *pointer*, and as such come
119//! in many flavors such as:
1a4d82fc 120//!
c1a9b12d
SL
121//! * `&[T]` - *shared slice*
122//! * `&mut [T]` - *mutable slice*
92a42be0 123//! * [`Box<[T]>`][owned slice] - *owned slice*
c1a9b12d 124//!
92a42be0
SL
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.
1a4d82fc 129//!
92a42be0
SL
130//! For converting to strings use the [`format!`] macro, and for converting from
131//! strings use the [`FromStr`] trait.
1a4d82fc 132//!
92a42be0
SL
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.
bd371182 138//!
92a42be0
SL
139//! The [`collections`] module defines maps, sets, linked lists and other
140//! typical collection types, including the common [`HashMap<K, V>`].
bd371182
AL
141//!
142//! ## Platform abstractions and I/O
1a4d82fc 143//!
92a42be0
SL
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], [UDP], are defined in the
149//! [`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//!
3dfed10e
XL
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
13cf67c4 174//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
3dfed10e
XL
175//! [`str`]: prim@str
176//! [`mpsc`]: sync::mpsc
177//! [`std::cmp`]: cmp
5869c6ff 178//! [`std::slice`]: mod@slice
92a42be0 179//! [`use std::env`]: env/index.html
532ac7d7 180//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html
92a42be0 181//! [crates.io]: https://crates.io
13cf67c4 182//! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
3dfed10e
XL
183//! [files]: fs::File
184//! [multithreading]: thread
92a42be0 185//! [other]: #what-is-in-the-standard-library-documentation
13cf67c4 186//! [primitive types]: ../book/ch03-02-data-types.html
ba9703b0 187//! [rust-discord]: https://discord.gg/rust-lang
6a06907d
XL
188//! [array]: prim@array
189//! [slice]: prim@slice
3dfed10e
XL
190#![cfg_attr(not(feature = "restricted-std"), stable(feature = "rust1", since = "1.0.0"))]
191#![cfg_attr(feature = "restricted-std", unstable(feature = "restricted_std", issue = "none"))]
dfeec247
XL
192#![doc(
193 html_root_url = "https://doc.rust-lang.org/nightly/",
194 html_playground_url = "https://play.rust-lang.org/",
195 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
196 test(no_crate_inject, attr(deny(warnings))),
197 test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
198)]
c30ab7b3
SL
199// Don't link to std. We are std.
200#![no_std]
416331ca 201#![warn(deprecated_in_future)]
48663c56
XL
202#![warn(missing_docs)]
203#![warn(missing_debug_implementations)]
532ac7d7 204#![allow(explicit_outlives_requirements)]
416331ca 205#![allow(unused_lifetimes)]
c30ab7b3 206// Tell the compiler to link to either panic_abort or panic_unwind
3157f602 207#![needs_panic_runtime]
c30ab7b3
SL
208// std may use features in a platform-specific way
209#![allow(unused_features)]
fc512014
XL
210#![feature(rustc_allow_const_fn_unstable)]
211#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count))]
dfeec247
XL
212#![cfg_attr(
213 all(target_vendor = "fortanix", target_env = "sgx"),
3dfed10e 214 feature(slice_index_methods, coerce_unsized, sgx_platform)
dfeec247 215)]
fc512014 216#![deny(rustc::existing_doc_keyword)]
3dfed10e 217#![cfg_attr(all(test, target_vendor = "fortanix", target_env = "sgx"), feature(fixed_size_array))]
c30ab7b3
SL
218// std is implemented with unstable features, many of which are internal
219// compiler details that will never be stable
9fa01778 220// NB: the following list is sorted to minimize merge conflicts.
8faf50e0 221#![feature(alloc_error_handler)]
9fa01778 222#![feature(alloc_layout_extra)]
8faf50e0 223#![feature(allocator_api)]
041b39d2 224#![feature(allocator_internals)]
3b2f2976 225#![feature(allow_internal_unsafe)]
d9579d0f 226#![feature(allow_internal_unstable)]
5869c6ff 227#![feature(async_stream)]
94b46f34 228#![feature(arbitrary_self_types)]
abe05a73 229#![feature(array_error_internals)]
92a42be0 230#![feature(asm)]
416331ca 231#![feature(associated_type_bounds)]
74b04a01 232#![feature(atomic_mut_ptr)]
1a4d82fc 233#![feature(box_syntax)]
a1dfa0c6 234#![feature(c_variadic)]
3dfed10e 235#![feature(cfg_accessible)]
6a06907d 236#![cfg_attr(not(bootstrap), feature(cfg_eval))]
c30ab7b3 237#![feature(cfg_target_has_atomic)]
9cc50fc6 238#![feature(cfg_target_thread_local)]
041b39d2 239#![feature(char_error_internals)]
f9f354fc 240#![feature(char_internals)]
0731742a 241#![feature(concat_idents)]
0bf4aa26 242#![feature(const_cstr_unchecked)]
29967ef6 243#![feature(const_fn_floating_point_arithmetic)]
3dfed10e 244#![feature(const_fn_transmute)]
1b1a35ee 245#![feature(const_fn)]
29967ef6
XL
246#![feature(const_fn_fn_ptr_basics)]
247#![feature(const_io_structs)]
1b1a35ee
XL
248#![feature(const_ip)]
249#![feature(const_ipv6)]
9fa01778 250#![feature(const_raw_ptr_deref)]
1b1a35ee 251#![feature(const_ipv4)]
e1599b0c 252#![feature(container_error_extra)]
62682a34 253#![feature(core_intrinsics)]
416331ca 254#![feature(custom_test_frameworks)]
e74abb32 255#![feature(decl_macro)]
9fa01778
XL
256#![feature(doc_cfg)]
257#![feature(doc_keyword)]
258#![feature(doc_masked)]
1b1a35ee 259#![feature(doc_spotlight)]
32a655c1 260#![feature(dropck_eyepatch)]
0731742a 261#![feature(duration_constants)]
29967ef6 262#![feature(duration_zero)]
5869c6ff 263#![feature(edition_panic)]
476ff2be 264#![feature(exact_size_is_empty)]
9fa01778 265#![feature(exhaustive_patterns)]
f9f354fc 266#![feature(extend_one)]
6a06907d 267#![feature(extended_key_value_attributes)]
54a0048b 268#![feature(fn_traits)]
416331ca 269#![feature(format_args_nl)]
f9f354fc 270#![feature(gen_future)]
8faf50e0 271#![feature(generator_trait)]
2a314972 272#![feature(get_mut_unchecked)]
416331ca 273#![feature(global_asm)]
0531ce1d 274#![feature(hashmap_internals)]
62682a34 275#![feature(int_error_internals)]
48663c56 276#![feature(int_error_matching)]
c30ab7b3 277#![feature(integer_atomics)]
3dfed10e 278#![feature(into_future)]
6a06907d 279#![feature(intra_doc_pointers)]
85aaf69f 280#![feature(lang_items)]
92a42be0
SL
281#![feature(link_args)]
282#![feature(linkage)]
ba9703b0 283#![feature(llvm_asm)]
416331ca 284#![feature(log_syntax)]
6a06907d 285#![feature(map_try_insert)]
3dfed10e 286#![feature(maybe_uninit_extra)]
416331ca
XL
287#![feature(maybe_uninit_ref)]
288#![feature(maybe_uninit_slice)]
5869c6ff 289#![feature(maybe_uninit_uninit_array)]
3dfed10e 290#![feature(min_specialization)]
5bcae85e 291#![feature(needs_panic_runtime)]
f9f354fc 292#![feature(negative_impls)]
cc61c64b 293#![feature(never_type)]
6a06907d 294#![feature(new_uninit)]
0bf4aa26 295#![feature(nll)]
3dfed10e
XL
296#![feature(nonnull_slice_from_raw_parts)]
297#![feature(once_cell)]
5869c6ff 298#![feature(auto_traits)]
ba9703b0 299#![feature(or_patterns)]
9fa01778 300#![feature(panic_info_message)]
0531ce1d 301#![feature(panic_internals)]
a7813a04 302#![feature(panic_unwind)]
2a314972 303#![feature(pin_static_ref)]
6a06907d 304#![feature(prelude_2021)]
9e0c209e 305#![feature(prelude_import)]
2c00a5a8 306#![feature(ptr_internals)]
62682a34 307#![feature(raw)]
3dfed10e 308#![feature(ready_macro)]
54a0048b 309#![feature(rustc_attrs)]
9fa01778 310#![feature(rustc_private)]
0531ce1d 311#![feature(shrink_to)]
92a42be0 312#![feature(slice_concat_ext)]
ff7c6d11 313#![feature(slice_internals)]
3dfed10e
XL
314#![feature(slice_ptr_get)]
315#![feature(slice_ptr_len)]
85aaf69f 316#![feature(staged_api)]
9fa01778
XL
317#![feature(std_internals)]
318#![feature(stdsimd)]
9cc50fc6 319#![feature(stmt_expr_attributes)]
62682a34 320#![feature(str_internals)]
416331ca 321#![feature(test)]
92a42be0 322#![feature(thread_local)]
1b1a35ee 323#![feature(thread_local_internals)]
cc61c64b 324#![feature(toowned_clone_into)]
f9f354fc 325#![feature(total_cmp)]
416331ca 326#![feature(trace_macros)]
fc512014 327#![feature(try_blocks)]
0531ce1d 328#![feature(try_reserve)]
85aaf69f 329#![feature(unboxed_closures)]
6a06907d 330#![cfg_attr(bootstrap, feature(unsafe_block_in_unsafe_fn))]
1b1a35ee 331#![feature(unsafe_cell_raw_get)]
e9174d1e 332#![feature(unwind_attributes)]
74b04a01 333#![feature(vec_into_raw_parts)]
5869c6ff 334#![feature(vec_spare_capacity)]
9fa01778 335// NB: the above list is sorted to minimize merge conflicts.
3b2f2976
XL
336#![default_lib_allocator]
337
c30ab7b3
SL
338// Explicitly import the prelude. The compiler uses this same unstable attribute
339// to import the prelude implicitly when building crates that depend on std.
9e0c209e
SL
340#[prelude_import]
341#[allow(unused)]
342use prelude::v1::*;
343
c30ab7b3 344// Access to Bencher, etc.
dfeec247
XL
345#[cfg(test)]
346extern crate test;
1a4d82fc 347
83c7162d 348#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
1a4d82fc 349#[macro_use]
83c7162d 350extern crate alloc as alloc_crate;
ea8adc8c 351#[doc(masked)]
532ac7d7 352#[allow(unused_extern_crates)]
1a4d82fc
JJ
353extern crate libc;
354
a7813a04 355// We always need an unwinder currently for backtraces
ea8adc8c 356#[doc(masked)]
3b2f2976 357#[allow(unused_extern_crates)]
a7813a04
XL
358extern crate unwind;
359
c30ab7b3
SL
360// During testing, this crate is not actually the "real" std library, but rather
361// it links to the real std library, which was compiled from this same source
362// code. So any lang items std defines are conditionally excluded (or else they
83c7162d 363// would generate duplicate lang item errors), and any globals it defines are
c30ab7b3
SL
364// _not_ the globals used by "real" std. So this import, defined only during
365// testing gives test-std access to real-std lang items and globals. See #2912
dfeec247
XL
366#[cfg(test)]
367extern crate std as realstd;
1a4d82fc 368
c30ab7b3
SL
369// The standard macros that are not built-in to the compiler.
370#[macro_use]
371mod macros;
372
373// The Rust prelude
374pub mod prelude;
1a4d82fc 375
2c00a5a8 376// Public module declarations and re-exports
92a42be0 377#[stable(feature = "rust1", since = "1.0.0")]
dfeec247
XL
378pub use alloc_crate::borrow;
379#[stable(feature = "rust1", since = "1.0.0")]
380pub use alloc_crate::boxed;
381#[stable(feature = "rust1", since = "1.0.0")]
382pub use alloc_crate::fmt;
383#[stable(feature = "rust1", since = "1.0.0")]
384pub use alloc_crate::format;
385#[stable(feature = "rust1", since = "1.0.0")]
386pub use alloc_crate::rc;
387#[stable(feature = "rust1", since = "1.0.0")]
388pub use alloc_crate::slice;
389#[stable(feature = "rust1", since = "1.0.0")]
390pub use alloc_crate::str;
391#[stable(feature = "rust1", since = "1.0.0")]
392pub use alloc_crate::string;
393#[stable(feature = "rust1", since = "1.0.0")]
394pub use alloc_crate::vec;
395#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 396pub use core::any;
9fa01778 397#[stable(feature = "simd_arch", since = "1.27.0")]
6a06907d
XL
398// The `no_inline`-attribute is required to make the documentation of all
399// targets available.
400// See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
401// more information.
402#[doc(no_inline)] // Note (#82861): required for correct documentation
9fa01778 403pub use core::arch;
dfeec247
XL
404#[stable(feature = "core_array", since = "1.36.0")]
405pub use core::array;
92a42be0 406#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 407pub use core::cell;
92a42be0 408#[stable(feature = "rust1", since = "1.0.0")]
dfeec247
XL
409pub use core::char;
410#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 411pub use core::clone;
92a42be0 412#[stable(feature = "rust1", since = "1.0.0")]
c1a9b12d 413pub use core::cmp;
92a42be0 414#[stable(feature = "rust1", since = "1.0.0")]
c34b1796 415pub use core::convert;
92a42be0 416#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 417pub use core::default;
5869c6ff
XL
418#[stable(feature = "futures_api", since = "1.36.0")]
419pub use core::future;
92a42be0 420#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 421pub use core::hash;
dfeec247
XL
422#[stable(feature = "core_hint", since = "1.27.0")]
423pub use core::hint;
424#[stable(feature = "i128", since = "1.26.0")]
5869c6ff 425#[allow(deprecated, deprecated_in_future)]
dfeec247
XL
426pub use core::i128;
427#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 428#[allow(deprecated, deprecated_in_future)]
dfeec247
XL
429pub use core::i16;
430#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 431#[allow(deprecated, deprecated_in_future)]
dfeec247
XL
432pub use core::i32;
433#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 434#[allow(deprecated, deprecated_in_future)]
dfeec247
XL
435pub use core::i64;
436#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 437#[allow(deprecated, deprecated_in_future)]
dfeec247 438pub use core::i8;
92a42be0 439#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 440pub use core::intrinsics;
92a42be0 441#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 442#[allow(deprecated, deprecated_in_future)]
dfeec247
XL
443pub use core::isize;
444#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 445pub use core::iter;
92a42be0 446#[stable(feature = "rust1", since = "1.0.0")]
c1a9b12d 447pub use core::marker;
92a42be0 448#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 449pub use core::mem;
92a42be0 450#[stable(feature = "rust1", since = "1.0.0")]
c1a9b12d 451pub use core::ops;
92a42be0 452#[stable(feature = "rust1", since = "1.0.0")]
dfeec247
XL
453pub use core::option;
454#[stable(feature = "pin", since = "1.33.0")]
455pub use core::pin;
456#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 457pub use core::ptr;
92a42be0 458#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 459pub use core::raw;
92a42be0 460#[stable(feature = "rust1", since = "1.0.0")]
1a4d82fc 461pub use core::result;
5869c6ff
XL
462#[unstable(feature = "async_stream", issue = "79024")]
463pub use core::stream;
0531ce1d 464#[stable(feature = "i128", since = "1.26.0")]
5869c6ff 465#[allow(deprecated, deprecated_in_future)]
dfeec247 466pub use core::u128;
92a42be0 467#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 468#[allow(deprecated, deprecated_in_future)]
e9174d1e 469pub use core::u16;
92a42be0 470#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 471#[allow(deprecated, deprecated_in_future)]
e9174d1e 472pub use core::u32;
92a42be0 473#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 474#[allow(deprecated, deprecated_in_future)]
e9174d1e 475pub use core::u64;
c30ab7b3 476#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 477#[allow(deprecated, deprecated_in_future)]
dfeec247 478pub use core::u8;
c30ab7b3 479#[stable(feature = "rust1", since = "1.0.0")]
5869c6ff 480#[allow(deprecated, deprecated_in_future)]
dfeec247 481pub use core::usize;
1a4d82fc 482
c30ab7b3
SL
483pub mod f32;
484pub mod f64;
1a4d82fc
JJ
485
486#[macro_use]
c34b1796 487pub mod thread;
c30ab7b3 488pub mod ascii;
e1599b0c 489pub mod backtrace;
c34b1796 490pub mod collections;
c34b1796 491pub mod env;
c30ab7b3 492pub mod error;
1a4d82fc 493pub mod ffi;
85aaf69f 494pub mod fs;
c34b1796 495pub mod io;
85aaf69f 496pub mod net;
c30ab7b3 497pub mod num;
1a4d82fc 498pub mod os;
9cc50fc6 499pub mod panic;
1a4d82fc 500pub mod path;
85aaf69f 501pub mod process;
c34b1796 502pub mod sync;
1a4d82fc 503pub mod time;
83c7162d 504
3dfed10e
XL
505#[unstable(feature = "once_cell", issue = "74465")]
506pub mod lazy;
507
48663c56 508#[stable(feature = "futures_api", since = "1.36.0")]
8faf50e0
XL
509pub mod task {
510 //! Types and Traits for working with asynchronous tasks.
ba9703b0 511
8faf50e0 512 #[doc(inline)]
48663c56 513 #[stable(feature = "futures_api", since = "1.36.0")]
8faf50e0 514 pub use core::task::*;
ba9703b0
XL
515
516 #[doc(inline)]
5869c6ff 517 #[stable(feature = "wake_trait", since = "1.51.0")]
ba9703b0 518 pub use alloc::task::*;
8faf50e0
XL
519}
520
c30ab7b3 521// Platform-abstraction modules
c34b1796 522#[macro_use]
c30ab7b3
SL
523mod sys_common;
524mod sys;
1a4d82fc 525
83c7162d
XL
526pub mod alloc;
527
c30ab7b3 528// Private support modules
c30ab7b3 529mod memchr;
dfeec247 530mod panicking;
c30ab7b3 531
c30ab7b3
SL
532// The runtime entry point and a few unstable public functions used by the
533// compiler
534pub mod rt;
ff7c6d11 535
3dfed10e
XL
536#[path = "../../backtrace/src/lib.rs"]
537#[allow(dead_code, unused_attributes)]
538mod backtrace_rs;
539
9fa01778 540// Pull in the `std_detect` crate directly into libstd. The contents of
416331ca 541// `std_detect` are in a different repository: rust-lang/stdarch.
0531ce1d 542//
9fa01778
XL
543// `std_detect` depends on libstd, but the contents of this module are
544// set up in such a way that directly pulling it here works such that the
545// crate uses the this crate as its libstd.
3dfed10e 546#[path = "../../stdarch/crates/std_detect/src/mod.rs"]
0531ce1d
XL
547#[allow(missing_debug_implementations, missing_docs, dead_code)]
548#[unstable(feature = "stdsimd", issue = "48556")]
0731742a 549#[cfg(not(test))]
9fa01778 550mod std_detect;
0531ce1d 551
9fa01778
XL
552#[doc(hidden)]
553#[unstable(feature = "stdsimd", issue = "48556")]
0731742a 554#[cfg(not(test))]
9fa01778 555pub use std_detect::detect;
9346a6ac 556
416331ca
XL
557// Re-export macros defined in libcore.
558#[stable(feature = "rust1", since = "1.0.0")]
e1599b0c 559#[allow(deprecated, deprecated_in_future)]
416331ca 560pub use core::{
36d6ef2b
XL
561 assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, r#try, todo,
562 unimplemented, unreachable, write, writeln,
416331ca
XL
563};
564
565// Re-export built-in macros defined through libcore.
416331ca 566#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
ba9703b0 567#[allow(deprecated)]
416331ca 568pub use core::{
ba9703b0
XL
569 asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
570 format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax,
571 module_path, option_env, stringify, trace_macros,
416331ca
XL
572};
573
74b04a01
XL
574#[stable(feature = "core_primitive", since = "1.43.0")]
575pub use core::primitive;
576
c1a9b12d
SL
577// Include a number of private modules that exist solely to provide
578// the rustdoc documentation for primitive types. Using `include!`
579// because rustdoc only looks for these modules at the crate level.
580include!("primitive_docs.rs");
94b46f34
XL
581
582// Include a number of private modules that exist solely to provide
583// the rustdoc documentation for the existing keywords. Using `include!`
584// because rustdoc only looks for these modules at the crate level.
585include!("keyword_docs.rs");
3dfed10e
XL
586
587// This is required to avoid an unstable error when `restricted-std` is not
588// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
589// is unconditional, so the unstable feature needs to be defined somewhere.
fc512014 590#[unstable(feature = "restricted_std", issue = "none")]
3dfed10e 591mod __restricted_std_workaround {}
6a06907d
XL
592
593mod sealed {
594 /// This trait being unreachable from outside the crate
595 /// prevents outside implementations of our extension traits.
596 /// This allows adding more trait methods in the future.
597 #[unstable(feature = "sealed", issue = "none")]
598 pub trait Sealed {}
599}