Skip to content

Commit 4e0b936

Browse files
committed
auto merge of #14513 : alexcrichton/rust/rustdoc-primitives, r=huonw
This is currently rebased on top of #14478, but that's just to preemptively avoid rebase conflicts and to provide a better preview. This can land independently of that PR. This change crates a dedicated page in rustdoc for primitive types to outline everything you can do with them (at least in a basic way). * Preview - http://people.mozilla.org/~acrichton/doc/ * Exhibit A - http://people.mozilla.org/~acrichton/doc/std/#primitives * Exhibit B - http://people.mozilla.org/~acrichton/doc/std/primitive.str.html * Exhibit C - http://people.mozilla.org/~acrichton/doc/std/primitive.slice.html Please don't hesitate to be nitpickity, it's easy to overlook a thing here or there!
2 parents 5527c5d + d58f27a commit 4e0b936

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+865
-384
lines changed

src/doc/complement-cheatsheet.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
**Int to string**
66

7-
Use [`ToStr`](../std/to_str/trait.ToStr.html).
7+
Use [`ToStr`](std/to_str/trait.ToStr.html).
88

99
~~~
1010
let x: int = 42;
@@ -13,8 +13,8 @@ let y: String = x.to_str().to_string();
1313

1414
**String to int**
1515

16-
Use [`FromStr`](../std/from_str/trait.FromStr.html), and its helper function,
17-
[`from_str`](../std/from_str/fn.from_str.html).
16+
Use [`FromStr`](std/from_str/trait.FromStr.html), and its helper function,
17+
[`from_str`](std/from_str/fn.from_str.html).
1818

1919
~~~
2020
let x: Option<int> = from_str("42");
@@ -35,8 +35,8 @@ let y: String = format!("{:X}", x); // uppercase hexadecimal
3535

3636
**String to int, in non-base-10**
3737

38-
Use [`FromStrRadix`](../std/num/trait.FromStrRadix.html), and its helper
39-
function, [`from_str_radix`](../std/num/fn.from_str_radix.html).
38+
Use [`FromStrRadix`](std/num/trait.FromStrRadix.html), and its helper
39+
function, [`from_str_radix`](std/num/fn.from_str_radix.html).
4040

4141
~~~
4242
use std::num;
@@ -48,7 +48,7 @@ let y: i64 = x.unwrap();
4848
**Vector of Bytes to String**
4949

5050
To return a Borrowed String Slice (&str) use the str helper function
51-
[`from_utf8`](../std/str/fn.from_utf8.html).
51+
[`from_utf8`](std/str/fn.from_utf8.html).
5252

5353
~~~
5454
use std::str;
@@ -58,7 +58,7 @@ let x: &str = str::from_utf8(bytes).unwrap();
5858
~~~
5959

6060
To return an Owned String use the str helper function
61-
[`from_utf8_owned`](../std/str/fn.from_utf8_owned.html).
61+
[`from_utf8_owned`](std/str/fn.from_utf8_owned.html).
6262

6363
~~~
6464
use std::str;
@@ -68,8 +68,8 @@ let x: Option<String> =
6868
let y: String = x.unwrap();
6969
~~~
7070

71-
To return a [`MaybeOwned`](../std/str/enum.MaybeOwned.html) use the str helper
72-
function [`from_utf8_lossy`](../std/str/fn.from_utf8_owned.html).
71+
To return a [`MaybeOwned`](std/str/type.MaybeOwned.html) use the str helper
72+
function [`from_utf8_lossy`](std/str/fn.from_utf8_owned.html).
7373
This function also replaces non-valid utf-8 sequences with U+FFFD replacement
7474
character.
7575

@@ -85,11 +85,11 @@ let y = str::from_utf8_lossy(x);
8585
## How do I read from a file?
8686

8787
Use
88-
[`File::open`](../std/io/fs/struct.File.html#method.open)
88+
[`File::open`](std/io/fs/struct.File.html#method.open)
8989
to create a
90-
[`File`](../std/io/fs/struct.File.html)
90+
[`File`](std/io/fs/struct.File.html)
9191
struct, which implements the
92-
[`Reader`](../std/io/trait.Reader.html)
92+
[`Reader`](std/io/trait.Reader.html)
9393
trait.
9494

9595
~~~ {.ignore}
@@ -103,7 +103,8 @@ let reader : File = File::open(&path).unwrap_or_else(on_error);
103103

104104
## How do I iterate over the lines in a file?
105105

106-
Use the [`lines`](../std/io/trait.Buffer.html#method.lines) method on a [`BufferedReader`](../std/io/buffered/struct.BufferedReader.html).
106+
Use the [`lines`](std/io/trait.Buffer.html#method.lines) method on a
107+
[`BufferedReader`](std/io/struct.BufferedReader.html).
107108

108109
~~~
109110
use std::io::BufferedReader;
@@ -121,7 +122,7 @@ for line in reader.lines() {
121122

122123
## How do I search for a substring?
123124

124-
Use the [`find_str`](../std/str/trait.StrSlice.html#tymethod.find_str) method.
125+
Use the [`find_str`](std/str/trait.StrSlice.html#tymethod.find_str) method.
125126

126127
~~~
127128
let str = "Hello, this is some random string";
@@ -132,7 +133,7 @@ let index: Option<uint> = str.find_str("rand");
132133

133134
## How do I get the length of a vector?
134135

135-
The [`Container`](../std/container/trait.Container.html) trait provides the `len` method.
136+
The [`Container`](std/container/trait.Container.html) trait provides the `len` method.
136137

137138
~~~
138139
let u: Vec<u32> = vec![0, 1, 2];
@@ -144,7 +145,7 @@ println!("u: {}, v: {}, w: {}", u.len(), v.len(), w.len()); // 3, 4, 5
144145

145146
## How do I iterate over a vector?
146147

147-
Use the [`iter`](../std/vec/trait.ImmutableVector.html#tymethod.iter) method.
148+
Use the [`iter`](std/slice/trait.ImmutableVector.html#tymethod.iter) method.
148149

149150
~~~
150151
let values: Vec<int> = vec![1, 2, 3, 4, 5];
@@ -153,9 +154,9 @@ for value in values.iter() { // value: &int
153154
}
154155
~~~
155156

156-
(See also [`mut_iter`](../std/vec/trait.MutableVector.html#tymethod.mut_iter)
157+
(See also [`mut_iter`](std/slice/trait.MutableVector.html#tymethod.mut_iter)
157158
which yields `&mut int` and
158-
[`move_iter`](../std/vec/trait.OwnedVector.html#tymethod.move_iter) which yields
159+
[`move_iter`](std/slice/trait.OwnedVector.html#tymethod.move_iter) which yields
159160
`int` while consuming the `values` vector.)
160161

161162
# Type system

src/doc/complement-lang-faq.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Some examples that demonstrate different aspects of the language:
2121
* The extra library's [json] module. Enums and pattern matching
2222

2323
[sprocketnes]: https://github.com/pcwalton/sprocketnes
24-
[hash]: https://github.com/mozilla/rust/blob/master/src/libstd/hash.rs
24+
[hash]: https://github.com/mozilla/rust/blob/master/src/libstd/hash/mod.rs
2525
[HashMap]: https://github.com/mozilla/rust/blob/master/src/libcollections/hashmap.rs
2626
[json]: https://github.com/mozilla/rust/blob/master/src/libserialize/json.rs
2727

@@ -149,6 +149,6 @@ example we were setting RUST_LOG to the name of the hello crate. Multiple paths
149149
can be combined to control the exact logging you want to see. For example, when
150150
debugging linking in the compiler you might set
151151
`RUST_LOG=rustc::metadata::creader,rustc::util::filesearch,rustc::back::rpath`
152-
For a full description see [the language reference][1].
152+
For a full description see [the logging crate][1].
153153

154-
[1]:http://doc.rust-lang.org/doc/master/rust.html#logging-system
154+
[1]:log/index.html

src/doc/guide-unsafe.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -499,9 +499,9 @@ shouldn't get triggered.
499499

500500
The second of these two functions, `eh_personality`, is used by the failure
501501
mechanisms of the compiler. This is often mapped to GCC's personality function
502-
(see the [libstd implementation](../std/rt/unwind/) for more information), but
503-
crates which do not trigger failure can be assured that this function is never
504-
called.
502+
(see the [libstd implementation](std/rt/unwind/index.html) for more
503+
information), but crates which do not trigger failure can be assured that this
504+
function is never called.
505505

506506
## Using libcore
507507

@@ -511,7 +511,8 @@ called.
511511
With the above techniques, we've got a bare-metal executable running some Rust
512512
code. There is a good deal of functionality provided by the standard library,
513513
however, that is necessary to be productive in Rust. If the standard library is
514-
not sufficient, then [libcore](../core/) is designed to be used instead.
514+
not sufficient, then [libcore](core/index.html) is designed to be used
515+
instead.
515516

516517
The core library has very few dependencies and is much more portable than the
517518
standard library itself. Additionally, the core library has most of the

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ pub mod arc;
9797
pub mod rc;
9898

9999
#[cfg(not(test))]
100+
#[doc(hidden)]
100101
mod std {
101102
pub use core::fmt;
102103
pub use core::option;

src/libcore/bool.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//!
1313
//! A `to_bit` conversion function.
1414
15+
#![doc(primitive = "bool")]
16+
1517
use num::{Int, one, zero};
1618

1719
/////////////////////////////////////////////////////////////////////////////

src/libcore/char.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
//! and, as such, should be performed via the `from_u32` function..
2525
2626
#![allow(non_snake_case_functions)]
27+
#![doc(primitive = "char")]
2728

2829
use mem::transmute;
2930
use option::{None, Option, Some};

src/libcore/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ pub mod fmt;
134134
// crate.
135135
mod should_not_exist;
136136

137+
#[doc(hidden)]
137138
mod core {
138139
pub use failure;
139140
}
140141

142+
#[doc(hidden)]
141143
mod std {
142144
pub use clone;
143145
pub use cmp;

src/libcore/num/f32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Operations and constants for 32-bits floats (`f32` type)
1212
13+
#![doc(primitive = "f32")]
14+
1315
use intrinsics;
1416
use mem;
1517
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};

src/libcore/num/f64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Operations and constants for 64-bits floats (`f64` type)
1212
13+
#![doc(primitive = "f64")]
14+
1315
use intrinsics;
1416
use mem;
1517
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};

src/libcore/num/i16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for signed 16-bits integers (`i16` type)
1212
13+
#![doc(primitive = "i16")]
14+
1315
int_module!(i16, 16)
1416

src/libcore/num/i32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for signed 32-bits integers (`i32` type)
1212
13+
#![doc(primitive = "i32")]
14+
1315
int_module!(i32, 32)
1416

src/libcore/num/i64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for signed 64-bits integers (`i64` type)
1212
13+
#![doc(primitive = "i64")]
14+
1315
int_module!(i64, 64)
1416

src/libcore/num/i8.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for signed 8-bits integers (`i8` type)
1212
13+
#![doc(primitive = "i8")]
14+
1315
int_module!(i8, 8)
1416

src/libcore/num/int.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
//! Operations and constants for architecture-sized signed integers (`int` type)
1212
13+
#![doc(primitive = "int")]
14+
1315
#[cfg(target_word_size = "32")] int_module!(int, 32)
1416
#[cfg(target_word_size = "64")] int_module!(int, 64)
1517

src/libcore/num/u16.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
//! Operations and constants for unsigned 16-bits integers (`u16` type)
1212
13+
#![doc(primitive = "u16")]
14+
1315
uint_module!(u16, i16, 16)

src/libcore/num/u32.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for unsigned 32-bits integers (`u32` type)
1212
13+
#![doc(primitive = "u32")]
14+
1315
uint_module!(u32, i32, 32)
1416

src/libcore/num/u64.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for unsigned 64-bits integer (`u64` type)
1212
13+
#![doc(primitive = "u64")]
14+
1315
uint_module!(u64, i64, 64)
1416

src/libcore/num/u8.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for unsigned 8-bits integers (`u8` type)
1212
13+
#![doc(primitive = "u8")]
14+
1315
uint_module!(u8, i8, 8)
1416

src/libcore/num/uint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010

1111
//! Operations and constants for architecture-sized unsigned integers (`uint` type)
1212
13+
#![doc(primitive = "uint")]
14+
1315
uint_module!(uint, int, ::int::BITS)
1416

src/libcore/result.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@
234234
//! similar and complementary: they are often employed to indicate a
235235
//! lack of a return value; and they are trivially converted between
236236
//! each other, so `Result`s are often handled by first converting to
237-
//! `Option` with the [`ok`](enum.Result.html#method.ok) and
238-
//! [`err`](enum.Result.html#method.ok) methods.
237+
//! `Option` with the [`ok`](type.Result.html#method.ok) and
238+
//! [`err`](type.Result.html#method.ok) methods.
239239
//!
240240
//! Whereas `Option` only indicates the lack of a value, `Result` is
241241
//! specifically for error reporting, and carries with it an error

src/libcore/slice.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//!
1313
//! For more details `std::slice`.
1414
15+
#![doc(primitive = "slice")]
16+
1517
use mem::transmute;
1618
use clone::Clone;
1719
use container::Container;

src/libcore/str.rs

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//!
1313
//! For more details, see std::str
1414
15+
#![doc(primitive = "str")]
16+
1517
use mem;
1618
use char;
1719
use clone::Clone;

src/libcore/tuple.rs

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
//! assert_eq!(d, (0u32, 0.0f32));
6060
//! ```
6161
62+
#![doc(primitive = "tuple")]
63+
6264
use clone::Clone;
6365
#[cfg(not(test))] use cmp::*;
6466
#[cfg(not(test))] use default::Default;

0 commit comments

Comments
 (0)