Skip to main content

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//! button</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>&nbsp;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//! `char`](primitive::char) that lists all the methods that can be called on
67//! characters (very useful), and there is a [page for the module
68//! `std::char`](crate::char) that documents iterator and error types created by these methods
69//! (rarely 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 [Zulip][t-libs-zulip]
98//! #t-libs.
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//! [TCP]: net::TcpStream
184//! [The Rust Prelude]: prelude
185//! [UDP]: net::UdpSocket
186//! [`Arc`]: sync::Arc
187//! [owned slice]: boxed
188//! [`Cell`]: cell::Cell
189//! [`FromStr`]: str::FromStr
190//! [`HashMap<K, V>`]: collections::HashMap
191//! [`Mutex`]: sync::Mutex
192//! [`Option<T>`]: option::Option
193//! [`Rc`]: rc::Rc
194//! [`RefCell`]: cell::RefCell
195//! [`Result<T, E>`]: result::Result
196//! [`Vec<T>`]: vec::Vec
197//! [`atomic`]: sync::atomic
198//! [`for`]: ../book/ch03-05-control-flow.html#looping-through-a-collection-with-for
199//! [`str`]: prim@str
200//! [`mpmc`]: sync::mpmc
201//! [`mpsc`]: sync::mpsc
202//! [`std::cmp`]: cmp
203//! [`std::slice`]: mod@slice
204//! [`use std::env`]: env/index.html
205//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html
206//! [crates.io]: https://crates.io
207//! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods
208//! [files]: fs::File
209//! [multithreading]: thread
210//! [other]: #what-is-in-the-standard-library-documentation
211//! [primitive types]: ../book/ch03-02-data-types.html
212//! [t-libs-zulip]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/
213//! [array]: prim@array
214//! [slice]: prim@slice
215
216#![cfg_attr(not(restricted_std), stable(feature = "rust1", since = "1.0.0"))]
217#![cfg_attr(
218    restricted_std,
219    unstable(
220        feature = "restricted_std",
221        issue = "none",
222        reason = "You have attempted to use a standard library built for a platform that it doesn't \
223            know how to support. Consider building it for a known environment, disabling it with \
224            `#![no_std]` or overriding this warning by enabling this feature."
225    )
226)]
227#![rustc_preserve_ub_checks]
228#![doc(
229    html_playground_url = "https://play.rust-lang.org/",
230    issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/",
231    test(no_crate_inject, attr(deny(warnings))),
232    test(attr(allow(dead_code, deprecated, unused_variables, unused_mut)))
233)]
234#![doc(rust_logo)]
235#![doc(auto_cfg(hide(no_global_oom_handling)))]
236// Don't link to std. We are std.
237#![no_std]
238// Tell the compiler to link to either panic_abort or panic_unwind
239#![needs_panic_runtime]
240//
241// Lints:
242#![warn(deprecated_in_future)]
243#![warn(missing_docs)]
244#![warn(missing_debug_implementations)]
245#![allow(explicit_outlives_requirements)]
246#![allow(unused_lifetimes)]
247#![allow(internal_features)]
248#![deny(implicit_provenance_casts)]
249#![deny(unsafe_op_in_unsafe_fn)]
250#![allow(rustdoc::redundant_explicit_links)]
251#![warn(rustdoc::unescaped_backticks)]
252// Ensure that std can be linked against panic_abort despite compiled with `-C panic=unwind`
253#![deny(ffi_unwind_calls)]
254// std may use features in a platform-specific way
255#![allow(unused_features)]
256//
257// Features:
258#![cfg_attr(
259    test,
260    feature(internal_output_capture, print_internals, super_let, update_panic_count, rt)
261)]
262#![cfg_attr(
263    all(target_vendor = "fortanix", target_env = "sgx"),
264    feature(slice_index_methods, coerce_unsized, sgx_platform)
265)]
266#![cfg_attr(all(test, target_os = "uefi"), feature(uefi_std))]
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#![feature(alloc_error_handler)]
273#![feature(allocator_internals)]
274#![feature(allow_internal_unsafe)]
275#![feature(allow_internal_unstable)]
276#![feature(asm_experimental_arch)]
277#![feature(autodiff)]
278#![feature(cfg_sanitizer_cfi)]
279#![feature(cfg_target_has_threads)]
280#![feature(cfg_target_thread_local)]
281#![feature(cfi_encoding)]
282#![feature(const_trait_impl)]
283#![feature(decl_macro)]
284#![feature(deprecated_suggestion)]
285#![feature(diagnostic_on_move)]
286#![feature(doc_cfg)]
287#![feature(doc_masked)]
288#![feature(doc_notable_trait)]
289#![feature(dropck_eyepatch)]
290#![feature(exact_div)]
291#![feature(f16)]
292#![feature(f128)]
293#![feature(ffi_const)]
294#![feature(gpu_offload)]
295#![feature(impl_restriction)]
296#![feature(intra_doc_pointers)]
297#![feature(lang_items)]
298#![feature(link_cfg)]
299#![feature(linkage)]
300#![feature(macro_metavar_expr_concat)]
301#![feature(min_specialization)]
302#![feature(must_not_suspend)]
303#![feature(needs_panic_runtime)]
304#![feature(negative_impls)]
305#![feature(never_type)]
306#![feature(optimize_attribute)]
307#![feature(prelude_import)]
308#![feature(rustc_attrs)]
309#![feature(rustdoc_internals)]
310#![feature(staged_api)]
311#![feature(stmt_expr_attributes)]
312#![feature(strict_provenance_lints)]
313#![feature(thread_local)]
314#![feature(try_blocks)]
315#![feature(try_trait_v2)]
316#![feature(type_alias_impl_trait)]
317#![feature(unwrap_infallible)]
318// tidy-alphabetical-end
319//
320// Library features (core):
321// tidy-alphabetical-start
322#![feature(borrowed_buf_init)]
323#![feature(bstr)]
324#![feature(bstr_internals)]
325#![feature(c_size_t)]
326#![feature(can_vector)]
327#![feature(cast_maybe_uninit)]
328#![feature(char_internals)]
329#![feature(clone_to_uninit)]
330#![feature(const_convert)]
331#![feature(const_default)]
332#![feature(core_float_math)]
333#![feature(core_intrinsics)]
334#![feature(core_io)]
335#![feature(core_io_borrowed_buf)]
336#![feature(core_io_internals)]
337#![feature(cstr_display)]
338#![feature(cursor_split)]
339#![feature(drop_guard)]
340#![feature(duration_constants)]
341#![feature(error_generic_member_access)]
342#![feature(error_iter)]
343#![feature(exact_size_is_empty)]
344#![feature(exclusive_wrapper)]
345#![feature(extend_one)]
346#![feature(float_gamma)]
347#![feature(float_minimum_maximum)]
348#![feature(fmt_internals)]
349#![feature(fn_ptr_trait)]
350#![feature(formatting_options)]
351#![feature(funnel_shifts)]
352#![feature(generic_atomic)]
353#![feature(hash_map_internals)]
354#![feature(hash_map_macro)]
355#![feature(hasher_prefixfree_extras)]
356#![feature(hashmap_internals)]
357#![feature(hint_must_use)]
358#![feature(int_from_ascii)]
359#![feature(io_error_inprogress)]
360#![feature(io_error_input_output_error)]
361#![feature(io_error_more)]
362#![feature(io_error_too_many_open_files)]
363#![feature(io_error_uncategorized)]
364#![feature(io_slice_as_bytes)]
365#![feature(ip)]
366#![feature(iter_advance_by)]
367#![feature(iter_next_chunk)]
368#![feature(maybe_dangling)]
369#![feature(maybe_uninit_array_assume_init)]
370#![feature(maybe_uninit_fill)]
371#![feature(panic_can_unwind)]
372#![feature(panic_internals)]
373#![feature(pin_coerce_unsized_trait)]
374#![feature(pointer_is_aligned_to)]
375#![feature(portable_simd)]
376#![feature(ptr_as_uninit)]
377#![feature(ptr_cast_slice)]
378#![feature(ptr_mask)]
379#![feature(random)]
380#![feature(raw_os_error_ty)]
381#![feature(seek_io_take_position)]
382#![feature(seek_stream_len)]
383#![feature(share_trait)]
384#![feature(slice_internals)]
385#![feature(slice_ptr_get)]
386#![feature(slice_range)]
387#![feature(slice_split_once)]
388#![feature(std_internals)]
389#![feature(str_internals)]
390#![feature(sync_unsafe_cell)]
391#![feature(temporary_niche_types)]
392#![feature(ub_checks)]
393#![feature(uint_carryless_mul)]
394#![feature(used_with_arg)]
395#![feature(write_all_vectored)]
396// tidy-alphabetical-end
397//
398// Library features (alloc):
399// tidy-alphabetical-start
400#![feature(alloc_io)]
401#![feature(allocator_api)]
402#![feature(clone_from_ref)]
403#![feature(get_mut_unchecked)]
404#![feature(map_try_insert)]
405#![feature(slice_concat_trait)]
406#![feature(thin_box)]
407#![feature(try_reserve_kind)]
408#![feature(try_with_capacity)]
409#![feature(unique_rc_arc)]
410#![feature(wtf8_internals)]
411// tidy-alphabetical-end
412//
413// Library features (unwind):
414// tidy-alphabetical-start
415#![feature(panic_unwind)]
416// tidy-alphabetical-end
417//
418// Library features (std_detect):
419// tidy-alphabetical-start
420#![feature(stdarch_internal)]
421// tidy-alphabetical-end
422//
423// Only for re-exporting:
424// tidy-alphabetical-start
425#![feature(async_iterator)]
426#![feature(c_variadic)]
427#![feature(cfg_accessible)]
428#![feature(cfg_eval)]
429#![feature(concat_bytes)]
430#![feature(const_format_args)]
431#![feature(custom_test_frameworks)]
432#![feature(edition_panic)]
433#![feature(format_args_nl)]
434#![feature(log_syntax)]
435#![feature(test)]
436#![feature(trace_macros)]
437// tidy-alphabetical-end
438//
439// Only used in tests/benchmarks:
440//
441// Only for const-ness:
442// tidy-alphabetical-start
443#![feature(io_const_error)]
444// tidy-alphabetical-end
445//
446#![default_lib_allocator]
447// Removed features
448#![unstable_removed(
449    feature = "concat_idents",
450    reason = "Replaced by the macro_metavar_expr_concat feature",
451    link = "https://github.com/rust-lang/rust/issues/29599#issuecomment-2986866250",
452    since = "1.90.0"
453)]
454
455// The Rust prelude
456// The compiler expects the prelude definition to be defined before its use statement.
457pub mod prelude;
458
459// Explicitly import the prelude. The compiler uses this same unstable attribute
460// to import the prelude implicitly when building crates that depend on std.
461#[prelude_import]
462#[allow(unused)]
463use prelude::rust_2024::*;
464
465// Access to Bencher, etc.
466#[cfg(test)]
467extern crate test;
468
469#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
470#[macro_use]
471extern crate alloc as alloc_crate;
472
473// Many compiler tests depend on libc being pulled in by std
474// so include it here even if it's unused.
475#[doc(masked)]
476#[allow(unused_extern_crates)]
477#[cfg(not(all(windows, target_env = "msvc")))]
478extern crate libc;
479
480// We always need an unwinder currently for backtraces
481#[doc(masked)]
482#[allow(unused_extern_crates)]
483extern crate unwind;
484
485// FIXME: #94122 this extern crate definition only exist here to stop
486// miniz_oxide docs leaking into std docs. Find better way to do it.
487// Remove exclusion from tidy platform check when this removed.
488#[doc(masked)]
489#[allow(unused_extern_crates)]
490#[cfg(all(
491    not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))),
492    feature = "miniz_oxide"
493))]
494extern crate miniz_oxide;
495
496// During testing, this crate is not actually the "real" std library, but rather
497// it links to the real std library, which was compiled from this same source
498// code. So any lang items std defines are conditionally excluded (or else they
499// would generate duplicate lang item errors), and any globals it defines are
500// _not_ the globals used by "real" std. So this import, defined only during
501// testing gives test-std access to real-std lang items and globals. See #2912
502#[cfg(test)]
503extern crate std as realstd;
504
505// The standard macros that are not built-in to the compiler.
506#[macro_use]
507mod macros;
508
509// The runtime entry point and a few unstable public functions used by the
510// compiler
511#[macro_use]
512pub mod rt;
513
514#[stable(feature = "rust1", since = "1.0.0")]
515pub use core::any;
516#[stable(feature = "core_array", since = "1.35.0")]
517pub use core::array;
518#[unstable(feature = "async_iterator", issue = "79024")]
519pub use core::async_iter;
520#[stable(feature = "rust1", since = "1.0.0")]
521pub use core::cell;
522#[stable(feature = "rust1", since = "1.0.0")]
523pub use core::char;
524#[stable(feature = "rust1", since = "1.0.0")]
525pub use core::clone;
526#[stable(feature = "rust1", since = "1.0.0")]
527pub use core::cmp;
528#[stable(feature = "rust1", since = "1.0.0")]
529pub use core::convert;
530#[stable(feature = "rust1", since = "1.0.0")]
531pub use core::default;
532#[unstable(feature = "field_projections", issue = "145383")]
533pub use core::field;
534#[stable(feature = "futures_api", since = "1.36.0")]
535pub use core::future;
536#[stable(feature = "core_hint", since = "1.27.0")]
537pub use core::hint;
538#[stable(feature = "rust1", since = "1.0.0")]
539#[allow(deprecated, deprecated_in_future)]
540pub use core::i8;
541#[stable(feature = "rust1", since = "1.0.0")]
542#[allow(deprecated, deprecated_in_future)]
543pub use core::i16;
544#[stable(feature = "rust1", since = "1.0.0")]
545#[allow(deprecated, deprecated_in_future)]
546pub use core::i32;
547#[stable(feature = "rust1", since = "1.0.0")]
548#[allow(deprecated, deprecated_in_future)]
549pub use core::i64;
550#[stable(feature = "i128", since = "1.26.0")]
551#[allow(deprecated, deprecated_in_future)]
552pub use core::i128;
553#[stable(feature = "rust1", since = "1.0.0")]
554pub use core::intrinsics;
555#[stable(feature = "rust1", since = "1.0.0")]
556#[allow(deprecated, deprecated_in_future)]
557pub use core::isize;
558#[stable(feature = "rust1", since = "1.0.0")]
559pub use core::iter;
560#[stable(feature = "rust1", since = "1.0.0")]
561pub use core::marker;
562#[stable(feature = "rust1", since = "1.0.0")]
563pub use core::mem;
564#[stable(feature = "rust1", since = "1.0.0")]
565pub use core::ops;
566#[stable(feature = "rust1", since = "1.0.0")]
567pub use core::option;
568#[stable(feature = "pin", since = "1.33.0")]
569pub use core::pin;
570#[stable(feature = "rust1", since = "1.0.0")]
571pub use core::ptr;
572#[stable(feature = "new_range_api", since = "1.96.0")]
573pub use core::range;
574#[stable(feature = "rust1", since = "1.0.0")]
575pub use core::result;
576#[stable(feature = "rust1", since = "1.0.0")]
577#[allow(deprecated, deprecated_in_future)]
578pub use core::u8;
579#[stable(feature = "rust1", since = "1.0.0")]
580#[allow(deprecated, deprecated_in_future)]
581pub use core::u16;
582#[stable(feature = "rust1", since = "1.0.0")]
583#[allow(deprecated, deprecated_in_future)]
584pub use core::u32;
585#[stable(feature = "rust1", since = "1.0.0")]
586#[allow(deprecated, deprecated_in_future)]
587pub use core::u64;
588#[stable(feature = "i128", since = "1.26.0")]
589#[allow(deprecated, deprecated_in_future)]
590pub use core::u128;
591#[unstable(feature = "unsafe_binders", issue = "130516")]
592pub use core::unsafe_binder;
593#[stable(feature = "rust1", since = "1.0.0")]
594#[allow(deprecated, deprecated_in_future)]
595pub use core::usize;
596
597#[stable(feature = "rust1", since = "1.0.0")]
598pub use alloc_crate::borrow;
599#[stable(feature = "rust1", since = "1.0.0")]
600pub use alloc_crate::boxed;
601#[stable(feature = "rust1", since = "1.0.0")]
602pub use alloc_crate::fmt;
603#[stable(feature = "rust1", since = "1.0.0")]
604pub use alloc_crate::format;
605#[stable(feature = "rust1", since = "1.0.0")]
606pub use alloc_crate::rc;
607#[stable(feature = "rust1", since = "1.0.0")]
608pub use alloc_crate::slice;
609#[stable(feature = "rust1", since = "1.0.0")]
610pub use alloc_crate::str;
611#[stable(feature = "rust1", since = "1.0.0")]
612pub use alloc_crate::string;
613#[stable(feature = "rust1", since = "1.0.0")]
614pub use alloc_crate::vec;
615
616#[path = "num/f128.rs"]
617pub mod f128;
618#[path = "num/f16.rs"]
619pub mod f16;
620#[path = "num/f32.rs"]
621pub mod f32;
622#[path = "num/f64.rs"]
623pub mod f64;
624
625#[macro_use]
626pub mod thread;
627pub mod ascii;
628pub mod backtrace;
629#[unstable(feature = "bstr", issue = "134915")]
630pub mod bstr;
631pub mod collections;
632pub mod env;
633pub mod error;
634pub mod ffi;
635pub mod fs;
636pub mod hash;
637pub mod io;
638pub mod net;
639pub mod num;
640pub mod os;
641pub mod panic;
642#[unstable(feature = "pattern_type_macro", issue = "123646")]
643pub mod pat;
644pub mod path;
645pub mod process;
646#[unstable(feature = "random", issue = "130703")]
647pub mod random;
648pub mod sync;
649pub mod time;
650#[cfg_attr(feature = "nightly", not(bootstrap))]
651#[unstable(feature = "view_type_macro", issue = "155938")]
652pub mod view;
653
654// Pull in `std_float` crate  into std. The contents of
655// `std_float` are in a different repository: rust-lang/portable-simd.
656#[path = "../../portable-simd/crates/std_float/src/lib.rs"]
657#[allow(missing_debug_implementations, dead_code, unsafe_op_in_unsafe_fn)]
658#[allow(rustdoc::bare_urls)]
659#[unstable(feature = "portable_simd", issue = "86656")]
660mod std_float;
661
662#[unstable(feature = "portable_simd", issue = "86656")]
663pub mod simd {
664    #![doc = include_str!("../../portable-simd/crates/core_simd/src/core_simd_docs.md")]
665
666    #[doc(inline)]
667    pub use core::simd::*;
668
669    #[doc(inline)]
670    pub use crate::std_float::StdFloat;
671}
672
673#[unstable(feature = "autodiff", issue = "124509")]
674#[doc = include_str!("../../core/src/autodiff.md")]
675pub mod autodiff {
676    /// This macro handles automatic differentiation.
677    pub use core::autodiff::{autodiff_forward, autodiff_reverse};
678}
679
680#[unstable(feature = "gpu_offload", issue = "131513")]
681#[doc = include_str!("../../core/src/offload.md")]
682pub mod offload {
683    pub use core::offload::{offload, offload_kernel};
684}
685
686#[stable(feature = "futures_api", since = "1.36.0")]
687pub mod task {
688    //! Types and Traits for working with asynchronous tasks.
689
690    #[doc(inline)]
691    #[stable(feature = "wake_trait", since = "1.51.0")]
692    pub use alloc::task::*;
693    #[doc(inline)]
694    #[stable(feature = "futures_api", since = "1.36.0")]
695    pub use core::task::*;
696}
697
698#[doc = include_str!("../../stdarch/crates/core_arch/src/core_arch_docs.md")]
699#[stable(feature = "simd_arch", since = "1.27.0")]
700pub mod arch {
701    #[stable(feature = "simd_arch", since = "1.27.0")]
702    // The `no_inline`-attribute is required to make the documentation of all
703    // targets available.
704    // See https://github.com/rust-lang/rust/pull/57808#issuecomment-457390549 for
705    // more information.
706    #[doc(no_inline)] // Note (#82861): required for correct documentation
707    pub use core::arch::*;
708
709    #[stable(feature = "simd_aarch64", since = "1.60.0")]
710    pub use std_detect::is_aarch64_feature_detected;
711    #[unstable(feature = "stdarch_arm_feature_detection", issue = "111190")]
712    pub use std_detect::is_arm_feature_detected;
713    #[unstable(feature = "is_loongarch_feature_detected", issue = "117425")]
714    pub use std_detect::is_loongarch_feature_detected;
715    #[unstable(feature = "is_riscv_feature_detected", issue = "111192")]
716    pub use std_detect::is_riscv_feature_detected;
717    #[stable(feature = "stdarch_s390x_feature_detection", since = "1.93.0")]
718    pub use std_detect::is_s390x_feature_detected;
719    #[stable(feature = "simd_x86", since = "1.27.0")]
720    pub use std_detect::is_x86_feature_detected;
721    #[unstable(feature = "stdarch_mips_feature_detection", issue = "111188")]
722    pub use std_detect::{is_mips_feature_detected, is_mips64_feature_detected};
723    #[unstable(feature = "stdarch_powerpc_feature_detection", issue = "111191")]
724    pub use std_detect::{is_powerpc_feature_detected, is_powerpc64_feature_detected};
725}
726
727// This was stabilized in the crate root so we have to keep it there.
728#[stable(feature = "simd_x86", since = "1.27.0")]
729pub use std_detect::is_x86_feature_detected;
730
731mod sys;
732
733pub mod alloc;
734
735// Private support modules
736mod panicking;
737
738#[path = "../../backtrace/src/lib.rs"]
739#[allow(dead_code, unused_attributes, implicit_provenance_casts, unsafe_op_in_unsafe_fn)]
740mod backtrace_rs;
741
742#[stable(feature = "cfg_select", since = "1.95.0")]
743pub use core::cfg_select;
744#[unstable(
745    feature = "concat_bytes",
746    issue = "87555",
747    reason = "`concat_bytes` is not stable enough for use and is subject to change"
748)]
749pub use core::concat_bytes;
750#[unstable(feature = "derive_macro_global_path", issue = "154645")]
751pub use core::derive;
752#[stable(feature = "matches_macro", since = "1.42.0")]
753#[allow(deprecated, deprecated_in_future)]
754pub use core::matches;
755#[stable(feature = "core_primitive", since = "1.43.0")]
756pub use core::primitive;
757#[stable(feature = "todo_macro", since = "1.40.0")]
758#[allow(deprecated, deprecated_in_future)]
759pub use core::todo;
760// Re-export built-in macros defined through core.
761#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
762pub use core::{
763    assert, cfg, column, compile_error, concat, const_format_args, env, file, format_args,
764    format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
765    stringify, trace_macros,
766};
767// Re-export macros defined in core.
768#[stable(feature = "rust1", since = "1.0.0")]
769#[allow(deprecated, deprecated_in_future)]
770pub use core::{
771    assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, r#try, unimplemented,
772    unreachable, write, writeln,
773};
774#[stable(feature = "assert_matches", since = "1.96.0")]
775pub use core::{assert_matches, debug_assert_matches};
776
777// Re-export unstable derive macro defined through core.
778#[unstable(feature = "derive_from", issue = "144889")]
779/// Unstable module containing the unstable `From` derive macro.
780pub mod from {
781    #[unstable(feature = "derive_from", issue = "144889")]
782    pub use core::from::From;
783}
784
785// We include the following files here *again* (they are already included in libcore)
786// so that they show up in search results for the std crate, and to avoid breaking
787// existing links:
788
789// documentation for built-in attributes. Using `include!` because rustdoc
790// only looks for these modules at the crate level.
791include!("../../core/src/attribute_docs.rs");
792
793// Include a number of private modules that exist solely to provide
794// the rustdoc documentation for the existing keywords. Using `include!`
795// because rustdoc only looks for these modules at the crate level.
796include!("../../core/src/keyword_docs.rs");
797
798// Include a number of private modules that exist solely to provide
799// the rustdoc documentation for primitive types. Using `include!`
800// because rustdoc only looks for these modules at the crate level.
801include!("../../core/src/primitive_docs.rs");
802
803// This is required to avoid an unstable error when `restricted-std` is not
804// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
805// is unconditional, so the unstable feature needs to be defined somewhere.
806#[unstable(feature = "restricted_std", issue = "none")]
807mod __restricted_std_workaround {}
808
809// FIXME(jhpratt) This is currently only used by portable SIMD. Once rust-lang/portable-simd#529 is
810// merged, this should be able to be removed.
811mod sealed {
812    /// This trait being unreachable from outside the crate
813    /// prevents outside implementations of our extension traits.
814    /// This allows adding more trait methods in the future.
815    #[unstable(feature = "sealed", issue = "none")]
816    pub trait Sealed {}
817}
818
819macro_rules! impl_sealed {
820    ($($t:ty)*) => {$(
821        /// Allows implementations within `std`.
822        #[unstable(feature = "sealed", issue = "none")]
823        impl crate::sealed::Sealed for $t {}
824    )*}
825}
826impl_sealed! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 f32 f64 }
827
828#[cfg(test)]
829#[allow(dead_code)] // Not used in all configurations.
830pub(crate) mod test_helpers;