std/lib.rs
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//! - 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//! [`mpmc`]: sync::mpmc
202//! [`mpsc`]: sync::mpsc
203//! [`std::cmp`]: cmp
204//! [`std::slice`]: mod@slice
205//! [`use std::env`]: env/index.html
206//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html
207//! [crates.io]: https://crates.io
208//! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
209//! [files]: fs::File
210//! [multithreading]: thread
211//! [other]: #what-is-in-the-standard-library-documentation
212//! [primitive types]: ../book/ch03-02-data-types.html
213//! [rust-discord]: https://discord.gg/rust-lang
214//! [array]: prim@array
215//! [slice]: prim@slice
216
217#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
218#![cfg_attr(
219 restricted_std,
220 unstable(
221 feature = "restricted_std",
222 issue = "none",
223 reason = "You have attempted to use a standard library built for a platform that it doesn't \
224 know how to support. Consider building it for a known environment, disabling it with \
225 `#![no_std]` or overriding this warning by enabling this feature."
226 )
227)]
228#![rustc_preserve_ub_checks]
229#![doc(
230 html_playground_url = "https://play.rust-lang.org/",
231 issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
232 test(no_crate_inject, attr(deny(warnings))),
233 test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
234)]
235#![doc(rust_logo)]
236#![doc(cfg_hide(
237 not(test),
238 not(any(test, bootstrap)),
239 no_global_oom_handling,
240 not(no_global_oom_handling)
241))]
242// Don't link to std. We are std.
243#![no_std]
244// Tell the compiler to link to either panic_abort or panic_unwind
245#![needs_panic_runtime]
246//
247// Lints:
248#![warn(deprecated_in_future)]
249#![warn(missing_docs)]
250#![warn(missing_debug_implementations)]
251#![allow(explicit_outlives_requirements)]
252#![allow(unused_lifetimes)]
253#![allow(internal_features)]
254#![deny(fuzzy_provenance_casts)]
255#![deny(unsafe_op_in_unsafe_fn)]
256#![allow(rustdoc::redundant_explicit_links)]
257#![warn(rustdoc::unescaped_backticks)]
258// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
259#![deny(ffi_unwind_calls)]
260// std may use features in a platform-specific way
261#![allow(unused_features)]
262//
263// Features:
264#![cfg_attr(test, feature(internal_output_capture, print_internals, update_panic_count, rt))]
265#![cfg_attr(
266 all(target_vendor = "fortanix", target_env = "sgx"),
267 feature(slice_index_methods, coerce_unsized, sgx_platform)
268)]
269#![cfg_attr(any(windows, target_os = "uefi"), feature(round_char_boundary))]
270#![cfg_attr(target_family = "wasm", feature(stdarch_wasm_atomic_wait))]
271#![cfg_attr(target_arch = "wasm64", feature(simd_wasm64))]
272//
273// Language features:
274// tidy-alphabetical-start
275
276// stabilization was reverted after it hit beta
277#![cfg_attr(not(bootstrap), feature(extended_varargs_abi_support))]
278#![feature(alloc_error_handler)]
279#![feature(allocator_internals)]
280#![feature(allow_internal_unsafe)]
281#![feature(allow_internal_unstable)]
282#![feature(asm_experimental_arch)]
283#![feature(autodiff)]
284#![feature(cfg_sanitizer_cfi)]
285#![feature(cfg_target_thread_local)]
286#![feature(cfi_encoding)]
287#![feature(concat_idents)]
288#![feature(decl_macro)]
289#![feature(deprecated_suggestion)]
290#![feature(doc_cfg)]
291#![feature(doc_cfg_hide)]
292#![feature(doc_masked)]
293#![feature(doc_notable_trait)]
294#![feature(dropck_eyepatch)]
295#![feature(f128)]
296#![feature(f16)]
297#![feature(formatting_options)]
298#![feature(if_let_guard)]
299#![feature(intra_doc_pointers)]
300#![feature(lang_items)]
301#![feature(let_chains)]
302#![feature(link_cfg)]
303#![feature(linkage)]
304#![feature(macro_metavar_expr_concat)]
305#![feature(maybe_uninit_fill)]
306#![feature(min_specialization)]
307#![feature(must_not_suspend)]
308#![feature(needs_panic_runtime)]
309#![feature(negative_impls)]
310#![feature(never_type)]
311#![feature(no_sanitize)]
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(type_alias_impl_trait)]
322// tidy-alphabetical-end
323//
324// Library features (core):
325// tidy-alphabetical-start
326#![feature(array_chunks)]
327#![feature(bstr)]
328#![feature(bstr_internals)]
329#![feature(c_str_module)]
330#![feature(char_internals)]
331#![feature(clone_to_uninit)]
332#![feature(core_intrinsics)]
333#![feature(core_io_borrowed_buf)]
334#![feature(duration_constants)]
335#![feature(error_generic_member_access)]
336#![feature(error_iter)]
337#![feature(exact_size_is_empty)]
338#![feature(exclusive_wrapper)]
339#![feature(extend_one)]
340#![feature(float_gamma)]
341#![feature(float_minimum_maximum)]
342#![feature(fmt_internals)]
343#![feature(hasher_prefixfree_extras)]
344#![feature(hashmap_internals)]
345#![feature(hint_must_use)]
346#![feature(ip)]
347#![feature(lazy_get)]
348#![feature(maybe_uninit_slice)]
349#![feature(maybe_uninit_write_slice)]
350#![feature(nonnull_provenance)]
351#![feature(panic_can_unwind)]
352#![feature(panic_internals)]
353#![feature(pin_coerce_unsized_trait)]
354#![feature(pointer_is_aligned_to)]
355#![feature(portable_simd)]
356#![feature(ptr_as_uninit)]
357#![feature(ptr_mask)]
358#![feature(random)]
359#![feature(slice_internals)]
360#![feature(slice_ptr_get)]
361#![feature(slice_range)]
362#![feature(std_internals)]
363#![feature(str_internals)]
364#![feature(strict_provenance_atomic_ptr)]
365#![feature(sync_unsafe_cell)]
366#![feature(temporary_niche_types)]
367#![feature(ub_checks)]
368#![feature(used_with_arg)]
369// tidy-alphabetical-end
370//
371// Library features (alloc):
372// tidy-alphabetical-start
373#![feature(alloc_layout_extra)]
374#![feature(allocator_api)]
375#![feature(get_mut_unchecked)]
376#![feature(map_try_insert)]
377#![feature(new_zeroed_alloc)]
378#![feature(slice_concat_trait)]
379#![feature(thin_box)]
380#![feature(try_reserve_kind)]
381#![feature(try_with_capacity)]
382#![feature(unique_rc_arc)]
383#![feature(vec_into_raw_parts)]
384// tidy-alphabetical-end
385//
386// Library features (unwind):
387// tidy-alphabetical-start
388#![feature(panic_unwind)]
389// tidy-alphabetical-end
390//
391// Library features (std_detect):
392// tidy-alphabetical-start
393#![feature(stdarch_internal)]
394// tidy-alphabetical-end
395//
396// Only for re-exporting:
397// tidy-alphabetical-start
398#![feature(assert_matches)]
399#![feature(async_iterator)]
400#![feature(c_variadic)]
401#![feature(cfg_accessible)]
402#![feature(cfg_eval)]
403#![feature(concat_bytes)]
404#![feature(const_format_args)]
405#![feature(custom_test_frameworks)]
406#![feature(edition_panic)]
407#![feature(format_args_nl)]
408#![feature(log_syntax)]
409#![feature(test)]
410#![feature(trace_macros)]
411// tidy-alphabetical-end
412//
413// Only used in tests/benchmarks:
414//
415// Only for const-ness:
416// tidy-alphabetical-start
417#![feature(io_const_error)]
418// tidy-alphabetical-end
419//
420#![default_lib_allocator]
421
422// Explicitly import the prelude. The compiler uses this same unstable attribute
423// to import the prelude implicitly when building crates that depend on std.
424#[prelude_import]
425#[allow(unused)]
426use prelude::rust_2021::*;
427
428// Access to Bencher, etc.
429#[cfg(test)]
430extern crate test;
431
432#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
433#[macro_use]
434extern crate alloc as alloc_crate;
435
436// Many compiler tests depend on libc being pulled in by std
437// so include it here even if it's unused.
438#[doc(masked)]
439#[allow(unused_extern_crates)]
440#[cfg(not(all(windows, target_env = "msvc")))]
441extern crate libc;
442
443// We always need an unwinder currently for backtraces
444#[doc(masked)]
445#[allow(unused_extern_crates)]
446extern crate unwind;
447
448// FIXME: #94122 this extern crate definition only exist here to stop
449// miniz_oxide docs leaking into std docs. Find better way to do it.
450// Remove exclusion from tidy platform check when this removed.
451#[doc(masked)]
452#[allow(unused_extern_crates)]
453#[cfg(all(
454 not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))),
455 feature = "miniz_oxide"
456))]
457extern crate miniz_oxide;
458
459// During testing, this crate is not actually the "real" std library, but rather
460// it links to the real std library, which was compiled from this same source
461// code. So any lang items std defines are conditionally excluded (or else they
462// would generate duplicate lang item errors), and any globals it defines are
463// _not_ the globals used by "real" std. So this import, defined only during
464// testing gives test-std access to real-std lang items and globals. See #2912
465#[cfg(test)]
466extern crate std as realstd;
467
468// The standard macros that are not built-in to the compiler.
469#[macro_use]
470mod macros;
471
472// The runtime entry point and a few unstable public functions used by the
473// compiler
474#[macro_use]
475pub mod rt;
476
477// The Rust prelude
478pub mod prelude;
479
480#[stable(feature = "rust1", since = "1.0.0")]
481pub use core::any;
482#[stable(feature = "core_array", since = "1.35.0")]
483pub use core::array;
484#[unstable(feature = "async_iterator", issue = "79024")]
485pub use core::async_iter;
486#[stable(feature = "rust1", since = "1.0.0")]
487pub use core::cell;
488#[stable(feature = "rust1", since = "1.0.0")]
489pub use core::char;
490#[stable(feature = "rust1", since = "1.0.0")]
491pub use core::clone;
492#[stable(feature = "rust1", since = "1.0.0")]
493pub use core::cmp;
494#[stable(feature = "rust1", since = "1.0.0")]
495pub use core::convert;
496#[stable(feature = "rust1", since = "1.0.0")]
497pub use core::default;
498#[stable(feature = "futures_api", since = "1.36.0")]
499pub use core::future;
500#[stable(feature = "core_hint", since = "1.27.0")]
501pub use core::hint;
502#[stable(feature = "rust1", since = "1.0.0")]
503#[allow(deprecated, deprecated_in_future)]
504pub use core::i8;
505#[stable(feature = "rust1", since = "1.0.0")]
506#[allow(deprecated, deprecated_in_future)]
507pub use core::i16;
508#[stable(feature = "rust1", since = "1.0.0")]
509#[allow(deprecated, deprecated_in_future)]
510pub use core::i32;
511#[stable(feature = "rust1", since = "1.0.0")]
512#[allow(deprecated, deprecated_in_future)]
513pub use core::i64;
514#[stable(feature = "i128", since = "1.26.0")]
515#[allow(deprecated, deprecated_in_future)]
516pub use core::i128;
517#[stable(feature = "rust1", since = "1.0.0")]
518pub use core::intrinsics;
519#[stable(feature = "rust1", since = "1.0.0")]
520#[allow(deprecated, deprecated_in_future)]
521pub use core::isize;
522#[stable(feature = "rust1", since = "1.0.0")]
523pub use core::iter;
524#[stable(feature = "rust1", since = "1.0.0")]
525pub use core::marker;
526#[stable(feature = "rust1", since = "1.0.0")]
527pub use core::mem;
528#[stable(feature = "rust1", since = "1.0.0")]
529pub use core::ops;
530#[stable(feature = "rust1", since = "1.0.0")]
531pub use core::option;
532#[stable(feature = "pin", since = "1.33.0")]
533pub use core::pin;
534#[stable(feature = "rust1", since = "1.0.0")]
535pub use core::ptr;
536#[unstable(feature = "new_range_api", issue = "125687")]
537pub use core::range;
538#[stable(feature = "rust1", since = "1.0.0")]
539pub use core::result;
540#[stable(feature = "rust1", since = "1.0.0")]
541#[allow(deprecated, deprecated_in_future)]
542pub use core::u8;
543#[stable(feature = "rust1", since = "1.0.0")]
544#[allow(deprecated, deprecated_in_future)]
545pub use core::u16;
546#[stable(feature = "rust1", since = "1.0.0")]
547#[allow(deprecated, deprecated_in_future)]
548pub use core::u32;
549#[stable(feature = "rust1", since = "1.0.0")]
550#[allow(deprecated, deprecated_in_future)]
551pub use core::u64;
552#[stable(feature = "i128", since = "1.26.0")]
553#[allow(deprecated, deprecated_in_future)]
554pub use core::u128;
555#[unstable(feature = "unsafe_binders", issue = "130516")]
556pub use core::unsafe_binder;
557#[stable(feature = "rust1", since = "1.0.0")]
558#[allow(deprecated, deprecated_in_future)]
559pub use core::usize;
560
561#[stable(feature = "rust1", since = "1.0.0")]
562pub use alloc_crate::borrow;
563#[stable(feature = "rust1", since = "1.0.0")]
564pub use alloc_crate::boxed;
565#[stable(feature = "rust1", since = "1.0.0")]
566pub use alloc_crate::fmt;
567#[stable(feature = "rust1", since = "1.0.0")]
568pub use alloc_crate::format;
569#[stable(feature = "rust1", since = "1.0.0")]
570pub use alloc_crate::rc;
571#[stable(feature = "rust1", since = "1.0.0")]
572pub use alloc_crate::slice;
573#[stable(feature = "rust1", since = "1.0.0")]
574pub use alloc_crate::str;
575#[stable(feature = "rust1", since = "1.0.0")]
576pub use alloc_crate::string;
577#[stable(feature = "rust1", since = "1.0.0")]
578pub use alloc_crate::vec;
579
580#[unstable(feature = "f128", issue = "116909")]
581pub mod f128;
582#[unstable(feature = "f16", issue = "116909")]
583pub mod f16;
584pub mod f32;
585pub mod f64;
586
587#[macro_use]
588pub mod thread;
589pub mod ascii;
590pub mod backtrace;
591#[unstable(feature = "bstr", issue = "134915")]
592pub mod bstr;
593pub mod collections;
594pub mod env;
595pub mod error;
596pub mod ffi;
597pub mod fs;
598pub mod hash;
599pub mod io;
600pub mod net;
601pub mod num;
602pub mod os;
603pub mod panic;
604#[unstable(feature = "pattern_type_macro", issue = "123646")]
605pub mod pat;
606pub mod path;
607pub mod process;
608#[unstable(feature = "random", issue = "130703")]
609pub mod random;
610pub mod sync;
611pub mod time;
612
613// Pull in `std_float` crate into std. The contents of
614// `std_float` are in a different repository: rust-lang/portable-simd.
615#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
616#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
617#[allow(rustdoc::bare_urls)]
618#[unstable(feature = "portable_simd", issue = "86656")]
619mod std_float;
620
621#[unstable(feature = "portable_simd", issue = "86656")]
622pub mod simd {
623 #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
624
625 #[doc(inline)]
626 pub use core::simd::*;
627
628 #[doc(inline)]
629 pub use crate::std_float::StdFloat;
630}
631#[unstable(feature = "autodiff", issue = "124509")]
632/// This module provides support for automatic differentiation.
633pub mod autodiff {
634 /// This macro handles automatic differentiation.
635 pub use core::autodiff::autodiff;
636}
637#[stable(feature = "futures_api", since = "1.36.0")]
638pub mod task {
639 //! Types and Traits for working with asynchronous tasks.
640
641 #[doc(inline)]
642 #[stable(feature = "wake_trait", since = "1.51.0")]
643 pub use alloc::task::*;
644 #[doc(inline)]
645 #[stable(feature = "futures_api", since = "1.36.0")]
646 pub use core::task::*;
647}
648
649#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
650#[stable(feature = "simd_arch", since = "1.27.0")]
651pub mod arch {
652 #[stable(feature = "simd_arch", since = "1.27.0")]
653 // The `no_inline`-attribute is required to make the documentation of all
654 // targets available.
655 // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
656 // more information.
657 #[doc(no_inline)] // Note (#82861): required for correct documentation
658 pub use core::arch::*;
659
660 #[stable(feature = "simd_aarch64", since = "1.60.0")]
661 pub use std_detect::is_aarch64_feature_detected;
662 #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")]
663 pub use std_detect::is_arm_feature_detected;
664 #[unstable(feature = "is_loongarch_feature_detected", issue = "117425")]
665 pub use std_detect::is_loongarch_feature_detected;
666 #[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
667 pub use std_detect::is_riscv_feature_detected;
668 #[stable(feature = "simd_x86", since = "1.27.0")]
669 pub use std_detect::is_x86_feature_detected;
670 #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
671 pub use std_detect::{is_mips_feature_detected, is_mips64_feature_detected};
672 #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
673 pub use std_detect::{is_powerpc_feature_detected, is_powerpc64_feature_detected};
674}
675
676// This was stabilized in the crate root so we have to keep it there.
677#[stable(feature = "simd_x86", since = "1.27.0")]
678pub use std_detect::is_x86_feature_detected;
679
680// Platform-abstraction modules
681mod sys;
682mod sys_common;
683
684pub mod alloc;
685
686// Private support modules
687mod panicking;
688
689#[path = "../../backtrace/src/lib.rs"]
690#[allow(dead_code, unused_attributes, fuzzy_provenance_casts, unsafe_op_in_unsafe_fn)]
691mod backtrace_rs;
692
693#[unstable(feature = "cfg_match", issue = "115585")]
694pub use core::cfg_match;
695#[unstable(
696 feature = "concat_bytes",
697 issue = "87555",
698 reason = "`concat_bytes` is not stable enough for use and is subject to change"
699)]
700pub use core::concat_bytes;
701#[stable(feature = "core_primitive", since = "1.43.0")]
702pub use core::primitive;
703// Re-export built-in macros defined through core.
704#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
705#[allow(deprecated)]
706pub use core::{
707 assert, assert_matches, cfg, column, compile_error, concat, concat_idents, const_format_args,
708 env, file, format_args, format_args_nl, include, include_bytes, include_str, line, log_syntax,
709 module_path, option_env, stringify, trace_macros,
710};
711// Re-export macros defined in core.
712#[stable(feature = "rust1", since = "1.0.0")]
713#[allow(deprecated, deprecated_in_future)]
714pub use core::{
715 assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, matches, todo, r#try,
716 unimplemented, unreachable, write, writeln,
717};
718
719// Include a number of private modules that exist solely to provide
720// the rustdoc documentation for primitive types. Using `include!`
721// because rustdoc only looks for these modules at the crate level.
722include!("../../core/src/primitive_docs.rs");
723
724// Include a number of private modules that exist solely to provide
725// the rustdoc documentation for the existing keywords. Using `include!`
726// because rustdoc only looks for these modules at the crate level.
727include!("keyword_docs.rs");
728
729// This is required to avoid an unstable error when `restricted-std` is not
730// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
731// is unconditional, so the unstable feature needs to be defined somewhere.
732#[unstable(feature = "restricted_std", issue = "none")]
733mod __restricted_std_workaround {}
734
735mod sealed {
736 /// This trait being unreachable from outside the crate
737 /// prevents outside implementations of our extension traits.
738 /// This allows adding more trait methods in the future.
739 #[unstable(feature = "sealed", issue = "none")]
740 pub trait Sealed {}
741}
742
743#[cfg(test)]
744#[allow(dead_code)] // Not used in all configurations.
745pub(crate) mod test_helpers;