|
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]`] (also called |
| 82 | +//! 'slice'). Many method calls on [`String`] and [`Vec<T>`] are actually calls |
| 83 | +//! to methods on [`str`] and [`[T]`] respectively, via [deref coercions]. |
| 84 | +//! |
| 85 | +//! Third, the standard library defines [The Rust Prelude], a small collection |
| 86 | +//! of items - mostly traits - that are imported into every module of every |
| 87 | +//! crate. The traits in the prelude are pervasive, making the prelude |
105 | 88 | //! documentation a good entry point to learning about the library.
|
106 | 89 | //!
|
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. |
| 90 | +//! And finally, the standard library exports a number of standard macros, and |
| 91 | +//! [lists them on this page](#macros) (technically, not all of the standard |
| 92 | +//! macros are defined by the standard library - some are defined by the |
| 93 | +//! compiler - but they are documented here the same). Like the prelude, the |
| 94 | +//! standard macros are imported by default into all crates. |
113 | 95 | //!
|
114 | 96 | //! # A Tour of The Rust Standard Library
|
115 | 97 | //!
|
116 |
| -//! The rest of this crate documentation is dedicated to pointing |
117 |
| -//! out notable features of The Rust Standard Library. |
| 98 | +//! The rest of this crate documentation is dedicated to pointing out notable |
| 99 | +//! features of The Rust Standard Library. |
118 | 100 | //!
|
119 | 101 | //! ## Containers and collections
|
120 | 102 | //!
|
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. |
| 103 | +//! The [`option`] and [`result`] modules define optional and error-handling |
| 104 | +//! types, [`Option<T>`] and [`Result<T, E>`]. The [`iter`] module defines |
| 105 | +//! Rust's iterator trait, [`Iterator`], which works with the [`for`] loop to |
| 106 | +//! access collections. |
127 | 107 | //!
|
128 |
| -//! The standard library exposes 3 common ways to deal with contiguous |
| 108 | +//! The standard library exposes three common ways to deal with contiguous |
129 | 109 | //! regions of memory:
|
130 | 110 | //!
|
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. |
| 111 | +//! * [`Vec<T>`] - A heap-allocated *vector* that is resizable at runtime. |
| 112 | +//! * [`[T; n]`] - An inline *array* with a fixed size at compile time. |
| 113 | +//! * [`[T]`] - A dynamically sized *slice* into any other kind of contiguous |
| 114 | +//! storage, whether heap-allocated or not. |
138 | 115 | //!
|
139 |
| -//! Slices can only be handled through some kind of *pointer*, and as |
140 |
| -//! such come in many flavors such as: |
| 116 | +//! Slices can only be handled through some kind of *pointer*, and as such come |
| 117 | +//! in many flavors such as: |
141 | 118 | //!
|
142 | 119 | //! * `&[T]` - *shared slice*
|
143 | 120 | //! * `&mut [T]` - *mutable slice*
|
144 |
| -//! * [`Box<[T]>`](boxed/index.html) - *owned slice* |
| 121 | +//! * [`Box<[T]>`] - *owned slice* |
145 | 122 | //!
|
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. |
| 123 | +//! [`str`], a UTF-8 string slice, is a primitive type, and the standard library |
| 124 | +//! defines many methods for it. Rust [`str`]s are typically accessed as |
| 125 | +//! immutable references: `&str`. Use the owned [`String`] for building and |
| 126 | +//! mutating strings. |
151 | 127 | //!
|
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. |
| 128 | +//! For converting to strings use the [`format!`] macro, and for converting from |
| 129 | +//! strings use the [`FromStr`] trait. |
155 | 130 | //!
|
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. |
| 131 | +//! Data may be shared by placing it in a reference-counted box or the [`Rc`] |
| 132 | +//! type, and if further contained in a [`Cell`] or [`RefCell`], may be mutated |
| 133 | +//! as well as shared. Likewise, in a concurrent setting it is common to pair an |
| 134 | +//! atomically-reference-counted box, [`Arc`], with a [`Mutex`] to get the same |
| 135 | +//! effect. |
162 | 136 | //!
|
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). |
| 137 | +//! The [`collections`] module defines maps, sets, linked lists and other |
| 138 | +//! typical collection types, including the common [`HashMap<K, V>`]. |
166 | 139 | //!
|
167 | 140 | //! ## Platform abstractions and I/O
|
168 | 141 | //!
|
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 |
| -//! |
| 142 | +//! Besides basic data types, the standard library is largely concerned with |
| 143 | +//! abstracting over differences in common platforms, most notably Windows and |
| 144 | +//! Unix derivatives. |
| 145 | +//! |
| 146 | +//! Common types of I/O, including [files], [TCP], [UDP], are defined in the |
| 147 | +//! [`io`], [`fs`], and [`net`] modules. |
| 148 | +//! |
| 149 | +//! The [`thread`] module contains Rust's threading abstractions. [`sync`] |
| 150 | +//! contains further primitive shared memory types, including [`atomic`] and |
| 151 | +//! [`mpsc`], which contains the channel types for message passing. |
| 152 | +//! |
| 153 | +//! [I/O]: io/index.html |
| 154 | +//! [MIN]: i32/constant.MIN.html |
| 155 | +//! [MAX]: i32/constant.MAX.html |
| 156 | +//! [TCP]: net/struct.TcpStream.html |
| 157 | +//! [The Rust Prelude]: prelude/index.html |
| 158 | +//! [UDP]: net/struct.UdpSocket.html |
| 159 | +//! [`::std::env::args()`]: env/fn.args.html |
| 160 | +//! [`Arc`]: sync/struct.Arc.html |
| 161 | +//! [`Box<[T]>`]: boxed/index.html |
| 162 | +//! [`Cell`]: cell/struct.Cell.html |
| 163 | +//! [`FromStr`]: str/trait.FromStr.html |
| 164 | +//! [`HashMap<K, V>`]: collections/struct.HashMap.html |
| 165 | +//! [`Iterator`]: iter/trait.Iterator.html |
| 166 | +//! [`Mutex`]: sync/struct.Mutex.html |
| 167 | +//! [`Option<T>`]: option/enum.Option.html |
| 168 | +//! [`Rc`]: rc/index.html |
| 169 | +//! [`RefCell`]: cell/struct.RefCell.html |
| 170 | +//! [`Result<T, E>`]: result/enum.Result.html |
| 171 | +//! [`String`]: string/struct.String.html |
| 172 | +//! [`Vec<T>`]: vec/index.html |
| 173 | +//! [`[T; n]`]: primitive.array.html |
| 174 | +//! [`[T]`]: primitive.slice.html |
| 175 | +//! [`atomic`]: sync/atomic/index.html |
| 176 | +//! [`collections`]: collections/index.html |
| 177 | +//! [`for`]: ../book/loops.html#for |
| 178 | +//! [`format!`]: macro.format!.html |
| 179 | +//! [`fs`]: fs/index.html |
| 180 | +//! [`io`]: io/index.html |
| 181 | +//! [`iter`]: iter/index.html |
| 182 | +//! [`mpsc`]: sync/mpsc/index.html |
| 183 | +//! [`net`]: net/index.html |
| 184 | +//! [`option`]: option/index.html |
| 185 | +//! [`result`]: result/index.html |
| 186 | +//! [`std::cmp`]: cmp/index.html |
| 187 | +//! [`std::slice`]: slice/index.html |
| 188 | +//! [`str`]: primitive.str.html |
| 189 | +//! [`sync`]: sync/index.html |
| 190 | +//! [`thread`]: thread/index.html |
| 191 | +//! [`use std::env`]: env/index.html |
| 192 | +//! [`use`]: ../book/crates-and-modules.html#importing-modules-with-use |
| 193 | +//! [crate root]: ../book/crates-and-modules.html#basic-terminology:-crates-and-modules |
| 194 | +//! [crates.io]: https://crates.io |
| 195 | +//! [deref coercions]: ../book/deref-coercions.html |
| 196 | +//! [files]: fs/struct.File.html |
| 197 | +//! [multithreading]: thread/index.html |
| 198 | +//! [other]: #what-is-in-the-standard-library-documentation |
| 199 | +//! [primitive types]: ../book/primitive-types.html |
186 | 200 |
|
187 | 201 | // Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
|
188 | 202 | #![cfg_attr(stage0, feature(custom_attribute))]
|
|
0 commit comments