|
10 | 10 |
|
11 | 11 | //! # The Rust Standard Library |
12 | 12 | //! |
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, like [`Vec`](vec/index.html) |
17 | | -//! and [`Option`](option/index.html), library-defined [operations on |
18 | | -//! language primitives](#primitives), [standard macros](#macros), |
19 | | -//! [I/O](io/index.html) and [multithreading](thread/index.html), among |
20 | | -//! [many other |
21 | | -//! things](#what-is-in-the-standard-library-documentation). |
22 | | -//! |
23 | | -//! `std` is available to all Rust crates by default, just as if each |
24 | | -//! one contained an `extern crate std` import at the [crate |
25 | | -//! root][book-crate-root]. Therefore the standard library can be |
26 | | -//! accessed in [`use`][book-use] statements through the path `std`, |
27 | | -//! as in [`use std::env`](env/index.html), or in expressions |
28 | | -//! through the absolute path `::std`, as in |
29 | | -//! [`::std::env::args()`](env/fn.args.html). |
30 | | -//! |
31 | | -//! [book-crate-root]: ../book/crates-and-modules.html#basic-terminology:-crates-and-modules |
32 | | -//! [book-use]: ../book/crates-and-modules.html#importing-modules-with-use |
| 13 | +//! The Rust Standard Library is the foundation of portable Rust software, a |
| 14 | +//! set of minimal and battle-tested shared abstractions for the [broader Rust |
| 15 | +//! ecosystem][crates.io]. It offers core types, like [`Vec<T>`] and |
| 16 | +//! [`Option<T>`], library-defined [operations on language |
| 17 | +//! primitives](#primitives), [standard macros](#macros), [I/O] and |
| 18 | +//! [multithreading], among [many other things][other]. |
| 19 | +//! |
| 20 | +//! `std` is available to all Rust crates by default, just as if each one |
| 21 | +//! contained an `extern crate std;` import at the [crate root]. Therefore the |
| 22 | +//! standard library can be accessed in [`use`] statements through the path |
| 23 | +//! `std`, as in [`use std::env`], or in expressions through the absolute path |
| 24 | +//! `::std`, as in [`::std::env::args()`]. |
33 | 25 | //! |
34 | 26 | //! # How to read this documentation |
35 | 27 | //! |
36 | | -//! If you already know the name of what you are looking for the |
37 | | -//! fastest way to find it is to use the <a href="#" |
38 | | -//! onclick="focusSearchBar();">search bar</a> at the top of the page. |
| 28 | +//! If you already know the name of what you are looking for the fastest way to |
| 29 | +//! find it is to use the <a href="#" onclick="focusSearchBar();">search |
| 30 | +//! bar</a> at the top of the page. |
39 | 31 | //! |
40 | 32 | //! Otherwise, you may want to jump to one of these useful sections: |
41 | 33 | //! |
|
44 | 36 | //! * [Standard macros](#macros) |
45 | 37 | //! * [The Rust Prelude](prelude/index.html) |
46 | 38 | //! |
47 | | -//! If this is your first time, the documentation for the standard |
48 | | -//! library is written to be casually perused. Clicking on interesting |
49 | | -//! things should generally lead you to interesting places. Still, |
50 | | -//! there are important bits you don't want to miss, so read on for a |
51 | | -//! tour of the standard library and its documentation! |
| 39 | +//! If this is your first time, the documentation for the standard library is |
| 40 | +//! written to be casually perused. Clicking on interesting things should |
| 41 | +//! generally lead you to interesting places. Still, there are important bits |
| 42 | +//! you don't want to miss, so read on for a tour of the standard library and |
| 43 | +//! its documentation! |
52 | 44 | //! |
53 | | -//! Once you are familiar with the contents of the standard library |
54 | | -//! you may begin to find the verbosity of the prose distracting. At |
55 | | -//! this stage in your development you may want to press the **[-]** |
56 | | -//! button near the top of the page to collapse it into a more |
57 | | -//! skimmable view. |
| 45 | +//! Once you are familiar with the contents of the standard library you may |
| 46 | +//! begin to find the verbosity of the prose distracting. At this stage in your |
| 47 | +//! development you may want to press the **[-]** button near the top of the |
| 48 | +//! page to collapse it into a more skimmable view. |
58 | 49 | //! |
59 | | -//! While you are looking at that **[-]** button also notice the |
60 | | -//! **[src]** button. Rust's API documentation comes with the source |
61 | | -//! code and you are encouraged to read it. The standard library |
62 | | -//! source is generally high quality and a peek behind the curtains is |
63 | | -//! often enlightening. |
| 50 | +//! While you are looking at that **[-]** button also notice the **[src]** |
| 51 | +//! button. Rust's API documentation comes with the source code and you are |
| 52 | +//! encouraged to read it. The standard library source is generally high |
| 53 | +//! quality and a peek behind the curtains is often enlightening. |
64 | 54 | //! |
65 | 55 | //! # What is in the standard library documentation? |
66 | 56 | //! |
67 | | -//! First of all, The Rust Standard Library is divided into a number |
68 | | -//! of focused modules, [all listed further down this page](#modules). |
69 | | -//! These modules are the bedrock upon which all of Rust is forged, |
70 | | -//! and they have mighty names like [`std::slice`](slice/index.html) |
71 | | -//! and [`std::cmp`](cmp/index.html). Modules' documentation typically |
72 | | -//! includes an overview of the module along with examples, and are |
73 | | -//! a smart place to start familiarizing yourself with the library. |
| 57 | +//! First of all, The Rust Standard Library is divided into a number of focused |
| 58 | +//! modules, [all listed further down this page](#modules). These modules are |
| 59 | +//! the bedrock upon which all of Rust is forged, and they have mighty names |
| 60 | +//! like [`std::slice`] and [`std::cmp`]. Modules' documentation typically |
| 61 | +//! includes an overview of the module along with examples, and are a smart |
| 62 | +//! place to start familiarizing yourself with the library. |
74 | 63 | //! |
75 | | -//! Second, implicit methods on [primitive |
76 | | -//! types](../book/primitive-types.html) are documented here. This can |
| 64 | +//! Second, implicit methods on [primitive types] are documented here. This can |
77 | 65 | //! be a source of confusion for two reasons: |
78 | 66 | //! |
79 | | -//! 1. While primitives are implemented by the compiler, the standard |
80 | | -//! library implements methods directly on the primitive types (and |
81 | | -//! it is the only library that does so), which are [documented in |
82 | | -//! the section on primitives](#primitives). |
83 | | -//! 2. The standard library exports many modules *with the same name |
84 | | -//! as primitive types*. These define additional items related |
85 | | -//! to the primitive type, but not the all-important methods. |
| 67 | +//! 1. While primitives are implemented by the compiler, the standard library |
| 68 | +//! implements methods directly on the primitive types (and it is the only |
| 69 | +//! library that does so), which are [documented in the section on |
| 70 | +//! primitives](#primitives). |
| 71 | +//! 2. The standard library exports many modules *with the same name as |
| 72 | +//! primitive types*. These define additional items related to the primitive |
| 73 | +//! type, but not the all-important methods. |
86 | 74 | //! |
87 | 75 | //! So for example there is a [page for the primitive type |
88 | | -//! `i32`](primitive.i32.html) that lists all the methods that can be |
89 | | -//! called on 32-bit integers (very useful), and there is a [page for |
90 | | -//! the module `std::i32`](i32/index.html) that documents the constant |
91 | | -//! values `MIN` and `MAX` (rarely useful). |
92 | | -//! |
93 | | -//! Note the documentation for the primitives |
94 | | -//! [`str`](primitive.str.html) and [`[T]`](primitive.slice.html) |
95 | | -//! (also called 'slice'). Many method calls on |
96 | | -//! [`String`](string/struct.String.html) and |
97 | | -//! [`Vec`](vec/struct.Vec.html) are actually calls to methods on |
98 | | -//! `str` and `[T]` respectively, via [deref |
99 | | -//! coercions](../book/deref-coercions.html). |
100 | | -//! |
101 | | -//! Third, the standard library defines [The Rust |
102 | | -//! Prelude](prelude/index.html), a small collection of items - mostly |
103 | | -//! traits - that are imported into every module of every crate. The |
104 | | -//! traits in the prelude are pervasive, making the prelude |
| 76 | +//! `i32`](primitive.i32.html) that lists all the methods that can be called on |
| 77 | +//! 32-bit integers (very useful), and there is a [page for the module |
| 78 | +//! `std::i32`](i32/index.html) that documents the constant values [`MIN`] and |
| 79 | +//! [`MAX`] (rarely useful). |
| 80 | +//! |
| 81 | +//! Note the documentation for the primitives [`str`] and [`[T]`][slice] (also |
| 82 | +//! called 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually |
| 83 | +//! calls to methods on [`str`] and [`[T]`][slice] respectively, via [deref |
| 84 | +//! coercions]. |
| 85 | +//! |
| 86 | +//! Third, the standard library defines [The Rust Prelude], a small collection |
| 87 | +//! of items - mostly traits - that are imported into every module of every |
| 88 | +//! crate. The traits in the prelude are pervasive, making the prelude |
105 | 89 | //! documentation a good entry point to learning about the library. |
106 | 90 | //! |
107 | | -//! And finally, the standard library exports a number of standard |
108 | | -//! macros, and [lists them on this page](#macros) (technically, not |
109 | | -//! all of the standard macros are defined by the standard library - |
110 | | -//! some are defined by the compiler - but they are documented here |
111 | | -//! the same). Like the prelude, the standard macros are imported by |
112 | | -//! default into all crates. |
| 91 | +//! And finally, the standard library exports a number of standard macros, and |
| 92 | +//! [lists them on this page](#macros) (technically, not all of the standard |
| 93 | +//! macros are defined by the standard library - some are defined by the |
| 94 | +//! compiler - but they are documented here the same). Like the prelude, the |
| 95 | +//! standard macros are imported by default into all crates. |
113 | 96 | //! |
114 | 97 | //! # A Tour of The Rust Standard Library |
115 | 98 | //! |
116 | | -//! The rest of this crate documentation is dedicated to pointing |
117 | | -//! out notable features of The Rust Standard Library. |
| 99 | +//! The rest of this crate documentation is dedicated to pointing out notable |
| 100 | +//! features of The Rust Standard Library. |
118 | 101 | //! |
119 | 102 | //! ## Containers and collections |
120 | 103 | //! |
121 | | -//! The [`option`](option/index.html) and |
122 | | -//! [`result`](result/index.html) modules define optional and |
123 | | -//! error-handling types, `Option` and `Result`. The |
124 | | -//! [`iter`](iter/index.html) module defines Rust's iterator trait, |
125 | | -//! [`Iterator`](iter/trait.Iterator.html), which works with the `for` |
126 | | -//! loop to access collections. |
| 104 | +//! The [`option`] and [`result`] modules define optional and error-handling |
| 105 | +//! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines |
| 106 | +//! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to |
| 107 | +//! access collections. |
127 | 108 | //! |
128 | | -//! The standard library exposes 3 common ways to deal with contiguous |
| 109 | +//! The standard library exposes three common ways to deal with contiguous |
129 | 110 | //! regions of memory: |
130 | 111 | //! |
131 | | -//! * [`Vec<T>`](vec/index.html) - A heap-allocated *vector* that is |
132 | | -//! resizable at runtime. |
133 | | -//! * [`[T; n]`](primitive.array.html) - An inline *array* with a |
134 | | -//! fixed size at compile time. |
135 | | -//! * [`[T]`](primitive.slice.html) - A dynamically sized *slice* into |
136 | | -//! any other kind of contiguous storage, whether heap-allocated or |
137 | | -//! not. |
| 112 | +//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime. |
| 113 | +//! * [`[T; n]`][array] - An inline *array* with a fixed size at compile time. |
| 114 | +//! * [`[T]`][slice] - A dynamically sized *slice* into any other kind of contiguous |
| 115 | +//! storage, whether heap-allocated or not. |
138 | 116 | //! |
139 | | -//! Slices can only be handled through some kind of *pointer*, and as |
140 | | -//! such come in many flavors such as: |
| 117 | +//! Slices can only be handled through some kind of *pointer*, and as such come |
| 118 | +//! in many flavors such as: |
141 | 119 | //! |
142 | 120 | //! * `&[T]` - *shared slice* |
143 | 121 | //! * `&mut [T]` - *mutable slice* |
144 | | -//! * [`Box<[T]>`](boxed/index.html) - *owned slice* |
| 122 | +//! * [`Box<[T]>`][owned slice] - *owned slice* |
145 | 123 | //! |
146 | | -//! `str`, a UTF-8 string slice, is a primitive type, and the standard |
147 | | -//! library defines [many methods for it](primitive.str.html). Rust |
148 | | -//! `str`s are typically accessed as immutable references: `&str`. Use |
149 | | -//! the owned `String` type defined in [`string`](string/index.html) |
150 | | -//! for building and mutating strings. |
| 124 | +//! [`str`], a UTF-8 string slice, is a primitive type, and the standard library |
| 125 | +//! defines many methods for it. Rust [`str`]s are typically accessed as |
| 126 | +//! immutable references: `&str`. Use the owned [`String`] for building and |
| 127 | +//! mutating strings. |
151 | 128 | //! |
152 | | -//! For converting to strings use the [`format!`](fmt/index.html) |
153 | | -//! macro, and for converting from strings use the |
154 | | -//! [`FromStr`](str/trait.FromStr.html) trait. |
| 129 | +//! For converting to strings use the [`format!`] macro, and for converting from |
| 130 | +//! strings use the [`FromStr`] trait. |
155 | 131 | //! |
156 | | -//! Data may be shared by placing it in a reference-counted box or the |
157 | | -//! [`Rc`](rc/index.html) type, and if further contained in a [`Cell` |
158 | | -//! or `RefCell`](cell/index.html), may be mutated as well as shared. |
159 | | -//! Likewise, in a concurrent setting it is common to pair an |
160 | | -//! atomically-reference-counted box, [`Arc`](sync/struct.Arc.html), |
161 | | -//! with a [`Mutex`](sync/struct.Mutex.html) to get the same effect. |
| 132 | +//! Data may be shared by placing it in a reference-counted box or the [`Rc`] |
| 133 | +//! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated |
| 134 | +//! as well as shared. Likewise, in a concurrent setting it is common to pair an |
| 135 | +//! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same |
| 136 | +//! effect. |
162 | 137 | //! |
163 | | -//! The [`collections`](collections/index.html) module defines maps, |
164 | | -//! sets, linked lists and other typical collection types, including |
165 | | -//! the common [`HashMap`](collections/struct.HashMap.html). |
| 138 | +//! The [`collections`] module defines maps, sets, linked lists and other |
| 139 | +//! typical collection types, including the common [`HashMap<K, V>`]. |
166 | 140 | //! |
167 | 141 | //! ## Platform abstractions and I/O |
168 | 142 | //! |
169 | | -//! Besides basic data types, the standard library is largely concerned |
170 | | -//! with abstracting over differences in common platforms, most notably |
171 | | -//! Windows and Unix derivatives. |
172 | | -//! |
173 | | -//! Common types of I/O, including [files](fs/struct.File.html), |
174 | | -//! [TCP](net/struct.TcpStream.html), |
175 | | -//! [UDP](net/struct.UdpSocket.html), are defined in the |
176 | | -//! [`io`](io/index.html), [`fs`](fs/index.html), and |
177 | | -//! [`net`](net/index.html) modules. |
178 | | -//! |
179 | | -//! The [`thread`](thread/index.html) module contains Rust's threading |
180 | | -//! abstractions. [`sync`](sync/index.html) contains further |
181 | | -//! primitive shared memory types, including |
182 | | -//! [`atomic`](sync/atomic/index.html) and |
183 | | -//! [`mpsc`](sync/mpsc/index.html), which contains the channel types |
184 | | -//! for message passing. |
185 | | -//! |
| 143 | +//! Besides basic data types, the standard library is largely concerned with |
| 144 | +//! abstracting over differences in common platforms, most notably Windows and |
| 145 | +//! Unix derivatives. |
| 146 | +//! |
| 147 | +//! Common types of I/O, including [files], [TCP], [UDP], are defined in the |
| 148 | +//! [`io`], [`fs`], and [`net`] modules. |
| 149 | +//! |
| 150 | +//! The [`thread`] module contains Rust's threading abstractions. [`sync`] |
| 151 | +//! contains further primitive shared memory types, including [`atomic`] and |
| 152 | +//! [`mpsc`], which contains the channel types for message passing. |
| 153 | +//! |
| 154 | +//! [I/O]: io/index.html |
| 155 | +//! [MIN]: i32/constant.MIN.html |
| 156 | +//! [MAX]: i32/constant.MAX.html |
| 157 | +//! [TCP]: net/struct.TcpStream.html |
| 158 | +//! [The Rust Prelude]: prelude/index.html |
| 159 | +//! [UDP]: net/struct.UdpSocket.html |
| 160 | +//! [`::std::env::args()`]: env/fn.args.html |
| 161 | +//! [`Arc`]: sync/struct.Arc.html |
| 162 | +//! [owned slice]: boxed/index.html |
| 163 | +//! [`Cell`]: cell/struct.Cell.html |
| 164 | +//! [`FromStr`]: str/trait.FromStr.html |
| 165 | +//! [`HashMap<K, V>`]: collections/struct.HashMap.html |
| 166 | +//! [`Iterator`]: iter/trait.Iterator.html |
| 167 | +//! [`Mutex`]: sync/struct.Mutex.html |
| 168 | +//! [`Option<T>`]: option/enum.Option.html |
| 169 | +//! [`Rc`]: rc/index.html |
| 170 | +//! [`RefCell`]: cell/struct.RefCell.html |
| 171 | +//! [`Result<T, E>`]: result/enum.Result.html |
| 172 | +//! [`String`]: string/struct.String.html |
| 173 | +//! [`Vec<T>`]: vec/index.html |
| 174 | +//! [array]: primitive.array.html |
| 175 | +//! [slice]: primitive.slice.html |
| 176 | +//! [`atomic`]: sync/atomic/index.html |
| 177 | +//! [`collections`]: collections/index.html |
| 178 | +//! [`for`]: ../book/loops.html#for |
| 179 | +//! [`format!`]: macro.format!.html |
| 180 | +//! [`fs`]: fs/index.html |
| 181 | +//! [`io`]: io/index.html |
| 182 | +//! [`iter`]: iter/index.html |
| 183 | +//! [`mpsc`]: sync/mpsc/index.html |
| 184 | +//! [`net`]: net/index.html |
| 185 | +//! [`option`]: option/index.html |
| 186 | +//! [`result`]: result/index.html |
| 187 | +//! [`std::cmp`]: cmp/index.html |
| 188 | +//! [`std::slice`]: slice/index.html |
| 189 | +//! [`str`]: primitive.str.html |
| 190 | +//! [`sync`]: sync/index.html |
| 191 | +//! [`thread`]: thread/index.html |
| 192 | +//! [`use std::env`]: env/index.html |
| 193 | +//! [`use`]: ../book/crates-and-modules.html#importing-modules-with-use |
| 194 | +//! [crate root]: ../book/crates-and-modules.html#basic-terminology:-crates-and-modules |
| 195 | +//! [crates.io]: https://crates.io |
| 196 | +//! [deref coercions]: ../book/deref-coercions.html |
| 197 | +//! [files]: fs/struct.File.html |
| 198 | +//! [multithreading]: thread/index.html |
| 199 | +//! [other]: #what-is-in-the-standard-library-documentation |
| 200 | +//! [primitive types]: ../book/primitive-types.html |
186 | 201 |
|
187 | 202 | // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364) |
188 | 203 | #![cfg_attr(stage0, feature(custom_attribute))] |
|
0 commit comments