Skip to content

Commit 68781e2

Browse files
committed
std: Refining crate docs
Yet another attempt to make the prose on the std crate page clearer and more informative. This does a lot of things: tightens up the opening, adds useful links (including a link to the search bar), offers guidance on how to use the docs, and expands the prelude docs as a useful newbie entrypoint.
1 parent 72483f5 commit 68781e2

File tree

2 files changed

+217
-33
lines changed

2 files changed

+217
-33
lines changed

src/libstd/lib.rs

Lines changed: 121 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,122 @@
1010

1111
//! # The Rust Standard Library
1212
//!
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?).
1523
//!
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).
31+
//!
32+
//! [book-crate-root]: file:///home/brian/dev/rust2/build/doc/book/crates-and-modules.html#basic-terminology:-crates-and-modules
33+
//! [book-use]: ../book/crates-and-modules.html#importing-modules-with-use
2234
//!
2335
//! Furthermore, the standard library defines [The Rust
2436
//! Prelude](prelude/index.html), a small collection of items, mostly
25-
//! traits, that are imported into and available in every module.
37+
//! traits, that are imported into every module and through trait
38+
//! resolution provide Rust with much of its *standard flavor*.
39+
//!
40+
//! # How to read this documentation
41+
//!
42+
//! If you already know the name of what you are looking for the
43+
//! fastest way to find it is to use the <a href="#"
44+
//! onclick="document.getElementsByName('search')[0].focus();">search
45+
//! bar</a> at the top of the page.
46+
//!
47+
//! Otherwise, you may want to jump to one of these useful sections:
48+
//!
49+
//! * [`std::*` modules](#modules)
50+
//! * [Primitive types](#primitives)
51+
//! * [Standard macros](#macros)
52+
//! * [The Rust Prelude](prelude/index.html)
53+
//!
54+
//! If this is your first time, the documentation for the standard
55+
//! library is written to be casually perused and clicking on
56+
//! interesting things should generally lead you to interesting
57+
//! places. Still, there are important bits you don't want to miss, so
58+
//! read on for a tour of the standard library and its documentation.
59+
//!
60+
//! Once you are familiar with the contents of the standard library
61+
//! you may begin to find the verbosity of the prose distracting. At
62+
//! this stage in your development you may want to press the **[-]**
63+
//! button near the top of the page to collapse it into a more
64+
//! skimmable view.
65+
//!
66+
//! While you are looking at that **[-]** button also notice the
67+
//! **[src]** button. Rust's API documentation comes with the source
68+
//! code and you are encouraged to read it. The standard library
69+
//! source is generally high quality and a peek behind the curtains is
70+
//! often enlightening.
71+
//!
72+
//! # What is in the standard library documentation?
2673
//!
27-
//! ## What is in the standard library
74+
//! Lots of stuff. Well, broadly four things actually.
2875
//!
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.
76+
//! First of all, The Rust Standard Library is divided into a number
77+
//! of focused modules, [all listed further down this page](#modules).
78+
//! These modules are the bedrock upon which all of Rust is forged,
79+
//! and they have mighty names like [`std::slice`](slice/index.html)
80+
//! and [`std::cmp`](cmp/index.html). Modules' documentation typically
81+
//! includes an overview of the module along with examples, and are
82+
//! a smart place to start familiarizing yourself with the library.
3283
//!
33-
//! The [primitive types](#primitives), though not defined in the
34-
//! standard library, are documented here, as are the predefined
35-
//! [macros](#macros).
84+
//! Secondly, implicit methods on [primitive
85+
//! types](../book/primitive-types.html) are documented here. This can
86+
//! be a source of confusion for two reasons:
87+
//!
88+
//! 1. While primitives are implemented by the compiler, the standard
89+
//! library implements methods directly on the primitive types (and
90+
//! it is the only library that does so), which are [documented in
91+
//! the section on primitives](#primitives).
92+
//! 2. The standard library exports many modules *with the same name
93+
//! as primitive types*. These define additional items related
94+
//! to the primitive type, but not the all-important methods.
95+
//!
96+
//! So for example there is a [page for the primitive type
97+
//! `i32`](primitive.i32.html) that lists all the methods that can be
98+
//! called on 32-bit integers (mega useful), and there is a [page for
99+
//! the module `std::i32`](i32/index.html) that documents the constant
100+
//! values `MIN` and `MAX` (rarely useful).
101+
//!
102+
//! Note the documentation for the primitives
103+
//! [`str`](primitive.str.html) and [`[T]`](primitive.slice.html)
104+
//! (also called 'slice'). Many method calls on
105+
//! [`String`](string/struct.String.html) and
106+
//! [`Vec`](vec/struct.Vec.html) are actually calls to methods on
107+
//! `str` and `[T]` respectively, via [deref
108+
//! coercions](../book/deref-coercions.html). *Accepting that
109+
//! primitive types are documented on their own pages will bring you a
110+
//! deep inner wisdom. Embrace it now before proceeding.*
111+
//!
112+
//! Thirdly, the standard library defines [The Rust
113+
//! Prelude](prelude/index.html), a small collection of items - mostly
114+
//! traits - that are imported into every module. The traits in the
115+
//! prelude are pervasive, making the prelude documentation a good
116+
//! entry point to learning about the library.
117+
//!
118+
//! And lastly, the standard library exports a number of standard
119+
//! macros, and [lists them on this page](#macros) (technically, not
120+
//! all of the standard macros are defined by the standard library -
121+
//! some are defined by the compiler - but they are documented here
122+
//! the same). Like the prelude, the standard macros are imported by
123+
//! default into all crates.
124+
//!
125+
//! # A Tour of The Rust Standard Library
126+
//!
127+
//! The rest of this crate documentation is dedicated to pointing
128+
//! out notable features of The Rust Standard Library.
36129
//!
37130
//! ## Containers and collections
38131
//!
@@ -43,17 +136,18 @@
43136
//! [`Iterator`](iter/trait.Iterator.html), which works with the `for`
44137
//! loop to access collections.
45138
//!
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.
139+
//! The common container type, `Vec`, a growable vector backed by an
140+
//! array, lives in the [`vec`](vec/index.html) module. Contiguous,
141+
//! unsized regions of memory, `[T]`, commonly called "slices", and
142+
//! their borrowed versions, `&[T]`, commonly called "borrowed
143+
//! slices", are primitive types [with many implicit
144+
//! methods](primitive.slice.html) defined by the standard library.
51145
//!
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.
146+
//! `str`, a UTF-8 string, is a primitive type, and the standard
147+
//! library defines [many methods for it](primitive.str.html).
148+
//! Rust `str`s are immutable; use the owned `String` type
149+
//! defined in [`string`](string/index.html) for building and mutating
150+
//! strings.
57151
//!
58152
//! For converting to strings use the [`format!`](fmt/index.html)
59153
//! macro, and for converting from strings use the
@@ -88,6 +182,7 @@
88182
//! [`atomic`](sync/atomic/index.html) and
89183
//! [`mpsc`](sync/mpsc/index.html), which contains the channel types
90184
//! for message passing.
185+
//!
91186
92187
// Do not remove on snapshot creation. Needed for bootstrap. (Issue #22364)
93188
#![cfg_attr(stage0, feature(custom_attribute))]

src/libstd/prelude/mod.rs

Lines changed: 96 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,107 @@
2222
//! with the `std::` path prefix, as in `use std::vec`, `use std::thread::spawn`,
2323
//! etc.
2424
//!
25-
//! Additionally, `std` contains a `prelude` module that reexports many of the
26-
//! most common traits, types and functions. The contents of the prelude are
27-
//! imported into every *module* by default. Implicitly, all modules behave as if
28-
//! they contained the following prologue:
25+
//! Additionally, `std` contains a versioned *prelude* that reexports many of the
26+
//! most common traits, types and functions. *The contents of the prelude are
27+
//! imported into every module by default*. Implicitly, all modules behave as if
28+
//! they contained the following [`use` statement][book-use]:
29+
//!
30+
//! [book-use]: ../../book/crates-and-modules.html#importing-modules-with-use
2931
//!
3032
//! ```ignore
3133
//! use std::prelude::v1::*;
3234
//! ```
3335
//!
34-
//! The prelude is primarily concerned with exporting *traits* that are so
35-
//! pervasive that it would be obnoxious to import for every use, particularly
36-
//! those that define methods on primitive types.
36+
//! The prelude is primarily concerned with exporting *traits* that
37+
//! are so pervasive that it would be onerous to import for every use,
38+
//! particularly those that are commonly mentioned in [generic type
39+
//! bounds][book-traits], and that are often used
40+
//!
41+
//! The current version of the prelude (version 1) lives in
42+
//! [`std::prelude::v1`](v1/index.html), and reexports the following.
43+
//!
44+
//! * `std::marker::`{
45+
//! [`Copy`](../marker/trait.Copy.html),
46+
//! [`Send`](../marker/trait.Send.html),
47+
//! [`Sized`](../marker/trait.Sized.html),
48+
//! [`Sync`](../marker/trait.Sync.html)
49+
//! }.
50+
//! The marker traits indicate fundamental properties of types.
51+
//! * `std::ops::`{
52+
//! [`Drop`](../ops/trait.Drop.html),
53+
//! [`Fn`](../ops/trait.Fn.html),
54+
//! [`FnMut`](../ops/trait.FnMut.html),
55+
//! [`FnOnce`](../ops/trait.FnOnce.html)
56+
//! }.
57+
//! The [destructor][book-dtor] trait and the
58+
//! [closure][book-closures] traits, reexported from the same
59+
//! [module that also defines overloaded
60+
//! operators](../ops/index.html).
61+
//! * `std::mem::`[`drop`](../mem/fn.drop.html).
62+
//! A convenience function for explicitly dropping a value.
63+
//! * `std::boxed::`[`Box`](../boxed/struct.Box.html).
64+
//! The owned heap pointer.
65+
//! * `std::borrow::`[`ToOwned`](../borrow/trait.ToOwned.html).
66+
//! The conversion trait that defines `to_owned`, the generic method
67+
//! for creating an owned type from a borrowed type.
68+
//! * `std::clone::`[`Clone`](../clone/trait.Clone.html).
69+
//! The ubiquitous trait that defines `clone`, the method for
70+
//! producing copies of values that are consider expensive to copy.
71+
//! * `std::cmp::`{
72+
//! [`PartialEq`](../cmp/trait.PartialEq.html),
73+
//! [`PartialOrd`](../cmp/trait.PartialOrd.html),
74+
//! [`Eq`](../cmp/trait.Eq.html),
75+
//! [`Ord`](../cmp/trait.Ord.html)
76+
//! }.
77+
//! The comparision traits, which implement the comparison operators
78+
//! and are often seen in trait bounds.
79+
//! * `std::convert::`{
80+
//! [`AsRef`](../convert/trait.AsRef.html),
81+
//! [`AsMut`](../convert/trait.AsMut.html),
82+
//! [`Into`](../convert/trait.Into.html),
83+
//! [`From`](../convert/trait.From.html)
84+
//! }.
85+
//! Generic conversions, used by savvy API authors to create
86+
//! overloaded methods.
87+
//! * `std::default::`[`Default`](../default/trait.Default).
88+
//! Types that have default values.
89+
//! * `std::iter::`{
90+
//! [`Iterator`](../iter/trait.Iterator.html),
91+
//! [`Extend`](../iter/trait.Extend.html),
92+
//! [`IntoIterator`](../iter/trait.IntoIterator.html),
93+
//! [`DoubleEndedIterator`](../iter/trait.DoubleEndedIterator.html),
94+
//! [`ExactSizeIterator`](../iter/trait.ExactSizeIterator.html)
95+
//! }.
96+
//! [Iterators][book-iter].
97+
//! * `std::option::Option::`{
98+
//! [`self`](../option/enum.Option.html),
99+
//! [`Some`](../option/enum.Option.html),
100+
//! [`None`](../option/enum.Option.html)
101+
//! }.
102+
//! The ubiquitous `Option` type and its two [variants][book-enums],
103+
//! `Some` and `None`.
104+
//! * `std::result::Result::`{
105+
//! [`self`](../result/enum.Result.html),
106+
//! [`Some`](../result/enum.Result.html),
107+
//! [`None`](../result/enum.Result.html)
108+
//! }.
109+
//! The ubiquitous `Result` type and its two [variants][book-enums],
110+
//! `Ok` and `Err`.
111+
//! * `std::slice::`[`SliceConcatExt`](../slice/trait.SliceConcatExt.html).
112+
//! An unstable extension to slices that shouldn't have to exist.
113+
//! * `std::string::`{
114+
//! [`String`](../string/struct.String.html),
115+
//! [`ToString`](../string/trait.ToString.html)
116+
//! }.
117+
//! Heap allocated strings.
118+
//! * `std::vec::`[`Vec`](../vec/struct.Vec.html).
119+
//! Heap allocated vectors.
120+
//!
121+
//! [book-traits]: ../../book/traits.html
122+
//! [book-closures]: ../../book/closures.html
123+
//! [book-dtor]: ../../book/drop.html
124+
//! [book-iter]: ../../book/iterators.html
125+
//! [book-enums]: ../../book/enums.html
37126
38127
#![stable(feature = "rust1", since = "1.0.0")]
39128

0 commit comments

Comments
 (0)