|
10 | 10 |
|
11 | 11 | //! # The Rust Standard Library
|
12 | 12 | //!
|
13 |
| -//! The Rust Standard Library provides the essential runtime |
14 |
| -//! functionality for building portable Rust software. |
| 13 | +//! The Rust Standard Library is the foundation of portable Rust |
| 14 | +//! software, a set of minimal and battle-tested shared abstractions |
| 15 | +//! for the [broader Rust ecosystem](https://crates.io). It offers |
| 16 | +//! core types (e.g. [`Vec`](vec/index.html) |
| 17 | +//! and [`Option`](option/index.html)), library-defined [operations on |
| 18 | +//! language primitives](#primitive) (e.g. [`u32`](u32/index.html) and |
| 19 | +//! [`str`](str/index.html)), [standard macros](#macros), |
| 20 | +//! [I/O](io/index.html) and [multithreading](thread/index.html), among |
| 21 | +//! [many other lovely |
| 22 | +//! things](#what-is-in-the-standard-library-documentation?). |
15 | 23 | //!
|
16 |
| -//! The Rust Standard Library is available to all Rust crates by |
17 |
| -//! default, just as if contained an `extern crate std` import at the |
18 |
| -//! crate root. Therefore the standard library can be accessed in |
19 |
| -//! `use` statements through the path `std`, as in `use std::thread`, |
20 |
| -//! or in expressions through the absolute path `::std`, as in |
21 |
| -//! `::std::thread::sleep_ms(100)`. |
| 24 | +//! `std` is available to all Rust crates by default, just as if each |
| 25 | +//! one contained an `extern crate std` import at the [crate |
| 26 | +//! root][book-crate-root]. Therefore the standard library can be |
| 27 | +//! accessed in [`use`][book-use] statements through the path `std`, |
| 28 | +//! as in [`use std::env`](env/index.html), or in expressions |
| 29 | +//! through the absolute path `::std`, as in |
| 30 | +//! [`::std::env::args()`](env/fn.args.html). |
22 | 31 | //!
|
23 |
| -//! Furthermore, the standard library defines [The Rust |
24 |
| -//! Prelude](prelude/index.html), a small collection of items, mostly |
25 |
| -//! traits, that are imported into and available in every module. |
| 32 | +//! [book-crate-root]: ../book/crates-and-modules.html#basic-terminology:-crates-and-modules |
| 33 | +//! [book-use]: ../book/crates-and-modules.html#importing-modules-with-use |
26 | 34 | //!
|
27 |
| -//! ## What is in the standard library |
| 35 | +//! # How to read this documentation |
28 | 36 | //!
|
29 |
| -//! The standard library is a set of minimal, battle-tested |
30 |
| -//! core types and shared abstractions for the [broader Rust |
31 |
| -//! ecosystem](https://crates.io) to build on. |
| 37 | +//! If you already know the name of what you are looking for the |
| 38 | +//! fastest way to find it is to use the <a href="#" |
| 39 | +//! onclick="focusSearchBar();">search bar</a> at the top of the page. |
32 | 40 | //!
|
33 |
| -//! The [primitive types](#primitives), though not defined in the |
34 |
| -//! standard library, are documented here, as are the predefined |
35 |
| -//! [macros](#macros). |
| 41 | +//! Otherwise, you may want to jump to one of these useful sections: |
| 42 | +//! |
| 43 | +//! * [`std::*` modules](#modules) |
| 44 | +//! * [Primitive types](#primitives) |
| 45 | +//! * [Standard macros](#macros) |
| 46 | +//! * [The Rust Prelude](prelude/index.html) |
| 47 | +//! |
| 48 | +//! If this is your first time, the documentation for the standard |
| 49 | +//! library is written to be casually perused. Clicking on interesting |
| 50 | +//! things should generally lead you to interesting places. Still, |
| 51 | +//! there are important bits you don't want to miss, so read on for a |
| 52 | +//! tour of the standard library and its documentation! |
| 53 | +//! |
| 54 | +//! Once you are familiar with the contents of the standard library |
| 55 | +//! you may begin to find the verbosity of the prose distracting. At |
| 56 | +//! this stage in your development you may want to press the **[-]** |
| 57 | +//! button near the top of the page to collapse it into a more |
| 58 | +//! skimmable view. |
| 59 | +//! |
| 60 | +//! While you are looking at that **[-]** button also notice the |
| 61 | +//! **[src]** button. Rust's API documentation comes with the source |
| 62 | +//! code and you are encouraged to read it. The standard library |
| 63 | +//! source is generally high quality and a peek behind the curtains is |
| 64 | +//! often enlightening. |
| 65 | +//! |
| 66 | +//! # What is in the standard library documentation? |
| 67 | +//! |
| 68 | +//! Lots of stuff. Well, broadly four things actually. |
| 69 | +//! |
| 70 | +//! First of all, The Rust Standard Library is divided into a number |
| 71 | +//! of focused modules, [all listed further down this page](#modules). |
| 72 | +//! These modules are the bedrock upon which all of Rust is forged, |
| 73 | +//! and they have mighty names like [`std::slice`](slice/index.html) |
| 74 | +//! and [`std::cmp`](cmp/index.html). Modules' documentation typically |
| 75 | +//! includes an overview of the module along with examples, and are |
| 76 | +//! a smart place to start familiarizing yourself with the library. |
| 77 | +//! |
| 78 | +//! Second, implicit methods on [primitive |
| 79 | +//! types](../book/primitive-types.html) are documented here. This can |
| 80 | +//! be a source of confusion for two reasons: |
| 81 | +//! |
| 82 | +//! 1. While primitives are implemented by the compiler, the standard |
| 83 | +//! library implements methods directly on the primitive types (and |
| 84 | +//! it is the only library that does so), which are [documented in |
| 85 | +//! the section on primitives](#primitives). |
| 86 | +//! 2. The standard library exports many modules *with the same name |
| 87 | +//! as primitive types*. These define additional items related |
| 88 | +//! to the primitive type, but not the all-important methods. |
| 89 | +//! |
| 90 | +//! So for example there is a [page for the primitive type |
| 91 | +//! `i32`](primitive.i32.html) that lists all the methods that can be |
| 92 | +//! called on 32-bit integers (mega useful), and there is a [page for |
| 93 | +//! the module `std::i32`](i32/index.html) that documents the constant |
| 94 | +//! values `MIN` and `MAX` (rarely useful). |
| 95 | +//! |
| 96 | +//! Note the documentation for the primitives |
| 97 | +//! [`str`](primitive.str.html) and [`[T]`](primitive.slice.html) |
| 98 | +//! (also called 'slice'). Many method calls on |
| 99 | +//! [`String`](string/struct.String.html) and |
| 100 | +//! [`Vec`](vec/struct.Vec.html) are actually calls to methods on |
| 101 | +//! `str` and `[T]` respectively, via [deref |
| 102 | +//! coercions](../book/deref-coercions.html). *Accepting that |
| 103 | +//! primitive types are documented on their own pages will bring you a |
| 104 | +//! deep inner wisdom. Embrace it now before proceeding.* |
| 105 | +//! |
| 106 | +//! Third, the standard library defines [The Rust |
| 107 | +//! Prelude](prelude/index.html), a small collection of items - mostly |
| 108 | +//! traits - that are imported into every module of every crate. The |
| 109 | +//! traits in the prelude are pervasive, making the prelude |
| 110 | +//! documentation a good entry point to learning about the library. |
| 111 | +//! |
| 112 | +//! And finally, the standard library exports a number of standard |
| 113 | +//! macros, and [lists them on this page](#macros) (technically, not |
| 114 | +//! all of the standard macros are defined by the standard library - |
| 115 | +//! some are defined by the compiler - but they are documented here |
| 116 | +//! the same). Like the prelude, the standard macros are imported by |
| 117 | +//! default into all crates. |
| 118 | +//! |
| 119 | +//! # A Tour of The Rust Standard Library |
| 120 | +//! |
| 121 | +//! The rest of this crate documentation is dedicated to pointing |
| 122 | +//! out notable features of The Rust Standard Library. |
36 | 123 | //!
|
37 | 124 | //! ## Containers and collections
|
38 | 125 | //!
|
|
43 | 130 | //! [`Iterator`](iter/trait.Iterator.html), which works with the `for`
|
44 | 131 | //! loop to access collections.
|
45 | 132 | //!
|
46 |
| -//! The common container type, `Vec`, a growable vector backed by an array, |
47 |
| -//! lives in the [`vec`](vec/index.html) module. Contiguous, unsized regions |
48 |
| -//! of memory, `[T]`, commonly called "slices", and their borrowed versions, |
49 |
| -//! `&[T]`, commonly called "borrowed slices", are built-in types for which the |
50 |
| -//! [`slice`](slice/index.html) module defines many methods. |
| 133 | +//! The standard library exposes 3 common ways to deal with contiguous |
| 134 | +//! regions of memory: |
51 | 135 | //!
|
52 |
| -//! `&str`, a UTF-8 string, is a built-in type, and the standard library |
53 |
| -//! defines methods for it on a variety of traits in the |
54 |
| -//! [`str`](str/index.html) module. Rust strings are immutable; |
55 |
| -//! use the `String` type defined in [`string`](string/index.html) |
56 |
| -//! for a mutable string builder. |
| 136 | +//! * [`Vec<T>`](vec/index.html) - A heap-allocated *vector* that is |
| 137 | +//! resizable at runtime. |
| 138 | +//! * [`[T; n]`](primitive.array.html) - An inline *array* with a |
| 139 | +//! fixed size at compile time. |
| 140 | +//! * [`[T]`](primitive.slice.html) - A dynamically sized *slice* into |
| 141 | +//! any other kind of contiguous storage, whether heap-allocated or |
| 142 | +//! not. |
| 143 | +//! |
| 144 | +//! Slices can only be handled through some kind of *pointer*, and as |
| 145 | +//! such come in many flavours such as: |
| 146 | +//! |
| 147 | +//! * `&[T]` - *shared slice* |
| 148 | +//! * `&mut [T]` - *mutable slice* |
| 149 | +//! * [`Box<[T]>`](boxed/index.html) - *owned slice* |
| 150 | +//! |
| 151 | +//! `str`, a UTF-8 string slice, is a primitive type, and the standard |
| 152 | +//! library defines [many methods for it](primitive.str.html). Rust |
| 153 | +//! `str`s are typically accessed as immutable references: `&str`. Use |
| 154 | +//! the owned `String` type defined in [`string`](string/index.html) |
| 155 | +//! for building and mutating strings. |
57 | 156 | //!
|
58 | 157 | //! For converting to strings use the [`format!`](fmt/index.html)
|
59 | 158 | //! macro, and for converting from strings use the
|
|
88 | 187 | //! [`atomic`](sync/atomic/index.html) and
|
89 | 188 | //! [`mpsc`](sync/mpsc/index.html), which contains the channel types
|
90 | 189 | //! for message passing.
|
| 190 | +//! |
91 | 191 |
|
92 | 192 | // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
|
93 | 193 | #![cfg_attr(stage0, feature(custom_attribute))]
|
|
0 commit comments