Skip to content

Commit 95f2c4b

Browse files
committed
auto merge of #13772 : brson/rust/cratedocs, r=alexcrichton
Also move prelude explanation to the prelude module. This tries to provide a guide to what's in the standard library, organized bottom up from primitives to I/O.
2 parents 7f6fa04 + 3525bd8 commit 95f2c4b

File tree

2 files changed

+106
-36
lines changed

2 files changed

+106
-36
lines changed

src/libstd/lib.rs

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,92 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! # The Rust standard library
11+
//! # The Rust Standard Library
1212
//!
13-
//! The Rust standard library is a group of interrelated modules defining
14-
//! the core language traits, operations on built-in data types,
15-
//! platform abstractions, the task scheduler, runtime support for language
16-
//! features and other common functionality.
13+
//! The Rust Standard Library provides the essential runtime
14+
//! functionality for building portable Rust software.
15+
//! It is linked to all Rust crates by default.
1716
//!
18-
//! `std` includes modules corresponding to each of the integer types,
19-
//! each of the floating point types, the `bool` type, tuples, characters,
20-
//! strings (`str`), vectors (`vec`), managed boxes (`managed`), owned
21-
//! boxes (`owned`), and unsafe pointers and references (`ptr`, `borrowed`).
22-
//! Additionally, `std` provides pervasive types (`option` and `result`),
23-
//! task creation and communication primitives (`task`, `comm`), platform
24-
//! abstractions (`os` and `path`), basic I/O abstractions (`io`), common
25-
//! traits (`kinds`, `ops`, `cmp`, `num`, `to_str`), and complete bindings
26-
//! to the C standard library (`libc`).
17+
//! ## Intrinsic types and operations
2718
//!
28-
//! # Standard library injection and the Rust prelude
19+
//! The [`ptr`](ptr/index.html), [`mem`](mem/index.html),
20+
//! and [`cast`](cast/index.html) modules deal with unsafe pointers,
21+
//! memory manipulation, and coercion.
22+
//! [`kinds`](kinds/index.html) defines the special built-in traits,
23+
//! and [`raw`](raw/index.html) the runtime representation of Rust types.
24+
//! These are some of the lowest-level building blocks of Rust
25+
//! abstractions.
2926
//!
30-
//! `std` is imported at the topmost level of every crate by default, as
31-
//! if the first line of each crate was
27+
//! ## Math on primitive types and math traits
3228
//!
33-
//! extern crate std;
29+
//! Although basic operations on primitive types are implemented
30+
//! directly by the compiler, the standard library additionally
31+
//! defines many common operations through traits defined in
32+
//! mod [`num`](num/index.html).
3433
//!
35-
//! This means that the contents of std can be accessed from any context
36-
//! with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
37-
//! etc.
34+
//! ## Pervasive types
3835
//!
39-
//! Additionally, `std` contains a `prelude` module that reexports many of the
40-
//! most common types, traits and functions. The contents of the prelude are
41-
//! imported into every *module* by default. Implicitly, all modules behave as if
42-
//! they contained the following prologue:
36+
//! The [`option`](option/index.html) and [`result`](result/index.html)
37+
//! modules define optional and error-handling types, `Option` and `Result`.
38+
//! [`iter`](iter/index.html) defines Rust's iterator protocol
39+
//! along with a wide variety of iterators.
40+
//! [`Cell` and `RefCell`](cell/index.html) are for creating types that
41+
//! manage their own mutability.
4342
//!
44-
//! use std::prelude::*;
43+
//! ## Vectors, slices and strings
44+
//!
45+
//! The common container type, `Vec`, a growable vector backed by an
46+
//! array, lives in the [`vec`](vec/index.html) module. References to
47+
//! arrays, `&[T]`, more commonly called "slices", are built-in types
48+
//! for which the [`slice`](slice/index.html) module defines many
49+
//! methods.
50+
//!
51+
//! UTF-8 strings, `~str` and `&str`, are built-in types, and the
52+
//! standard library defines methods for them on a variety of traits
53+
//! in the [`str`](str/index.html) module. Rust strings are immutable;
54+
//! use the `StrBuf` type defined in [`strbuf`](strbuf/index.html)
55+
//! for a mutable string builder.
56+
//!
57+
//! For converting to strings use the [`format!`](fmt/index.html)
58+
//! macro, and for converting from strings use the
59+
//! [`FromStr`](from_str/index.html) trait.
60+
//!
61+
//! ## Platform abstractions
62+
//!
63+
//! Besides basic data types, the standard library is largely concerned
64+
//! with abstracting over differences in common platforms, most notably
65+
//! Windows and Unix derivatives. The [`os`](os/index.html) module
66+
//! provides a number of basic functions for interacting with the
67+
//! operating environment, including program arguments, environment
68+
//! variables, and directory navigation. The [`path`](path/index.html)
69+
//! module encapsulates the platform-specific rules for dealing
70+
//! with file paths.
71+
//!
72+
//! `std` also includes modules for interoperating with the
73+
//! C language: [`c_str`](c_str/index.html) and
74+
//! [`c_vec`](c_vec/index.html).
75+
//!
76+
//! ## Concurrency, I/O, and the runtime
77+
//!
78+
//! The [`task`](task/index.html) module contains Rust's threading abstractions,
79+
//! while [`comm`](comm/index.html) contains the channel types for message
80+
//! passing. [`sync`](sync/index.html) contains further, primitive, shared
81+
//! memory types, including [`atomics`](sync/atomics/index.html).
82+
//!
83+
//! Common types of I/O, including files, TCP, UPD, pipes, Unix domain sockets,
84+
//! timers, and process spawning, are defined in the [`io`](io/index.html).
85+
//!
86+
//! Rust's I/O and concurrency depends on a small runtime interface
87+
//! that lives, along with its support code, in mod [`rt`](rt/index.html).
88+
//! While a notable part of the standard library's architecture, this
89+
//! module is not intended for public use.
90+
//!
91+
//! ## The Rust prelude and macros
92+
//!
93+
//! Finally, the [`prelude`](prelude/index.html) defines a set of
94+
//! common set of traits, types, and functions that are made available
95+
//! to all code by default. [`macros`](macros/index.html) contains
96+
//! all the standard macros, such as `assert!`, `fail!`, `println!`.
4597
4698
#![crate_id = "std#0.11-pre"]
4799
#![comment = "The Rust standard library"]

src/libstd/prelude.rs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,34 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/*!
12-
13-
The standard module imported by default into all Rust modules
14-
15-
Many programming languages have a 'prelude': a particular subset of the
16-
libraries that come with the language. Every program imports the prelude by
17-
default. The prelude imports various core parts of the library that are
18-
generally useful to many Rust programs.
19-
20-
*/
11+
//! # The Rust prelude
12+
//!
13+
//! Because `std` is required by most serious Rust software, it is
14+
//! imported at the topmost level of every crate by default, as if the
15+
//! first line of each crate was
16+
//!
17+
//! ```ignore
18+
//! extern crate std;
19+
//! ```
20+
//!
21+
//! This means that the contents of std can be accessed from any context
22+
//! with the `std::` path prefix, as in `use std::vec`, `use std::task::spawn`,
23+
//! etc.
24+
//!
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:
29+
//!
30+
//! ```ignore
31+
//! use std::prelude::*;
32+
//! ```
33+
//!
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. It does include a few
37+
//! particularly useful standalone functions, like `from_str`, `range`, and
38+
//! `drop`, `spawn`, and `channel`.
2139
2240
// Reexported core operators
2341
pub use kinds::{Copy, Send, Sized, Share};

0 commit comments

Comments
 (0)