|
12 | 12 | //!
|
13 | 13 | //! The `std::io` module contains a number of common things you'll need
|
14 | 14 | //! when doing input and output. The most core part of this module is
|
15 |
| -//! the [`Read`][read] and [`Write`][write] traits, which provide the |
| 15 | +//! the [`Read`] and [`Write`] traits, which provide the |
16 | 16 | //! most general interface for reading and writing input and output.
|
17 | 17 | //!
|
18 |
| -//! [read]: trait.Read.html |
19 |
| -//! [write]: trait.Write.html |
20 |
| -//! |
21 | 18 | //! # Read and Write
|
22 | 19 | //!
|
23 |
| -//! Because they are traits, `Read` and `Write` are implemented by a number |
| 20 | +//! Because they are traits, [`Read`] and [`Write`] are implemented by a number |
24 | 21 | //! of other types, and you can implement them for your types too. As such,
|
25 | 22 | //! you'll see a few different types of I/O throughout the documentation in
|
26 |
| -//! this module: `File`s, `TcpStream`s, and sometimes even `Vec<T>`s. For |
| 23 | +//! this module: [`File`]s, [`TcpStream`]s, and sometimes even [`Vec<T>`]s. For |
27 | 24 | //! example, `Read` adds a `read()` method, which we can use on `File`s:
|
28 | 25 | //!
|
29 | 26 | //! ```
|
|
43 | 40 | //! # }
|
44 | 41 | //! ```
|
45 | 42 | //!
|
46 |
| -//! `Read` and `Write` are so important, implementors of the two traits have a |
| 43 | +//! [`Read`] and [`Write`] are so important, implementors of the two traits have a |
47 | 44 | //! nickname: readers and writers. So you'll sometimes see 'a reader' instead
|
48 |
| -//! of 'a type that implements the `Read` trait'. Much easier! |
| 45 | +//! of 'a type that implements the [`Read`] trait'. Much easier! |
49 | 46 | //!
|
50 | 47 | //! ## Seek and BufRead
|
51 | 48 | //!
|
52 |
| -//! Beyond that, there are two important traits that are provided: [`Seek`][seek] |
53 |
| -//! and [`BufRead`][bufread]. Both of these build on top of a reader to control |
54 |
| -//! how the reading happens. `Seek` lets you control where the next byte is |
| 49 | +//! Beyond that, there are two important traits that are provided: [`Seek`] |
| 50 | +//! and [`BufRead`]. Both of these build on top of a reader to control |
| 51 | +//! how the reading happens. [`Seek`] lets you control where the next byte is |
55 | 52 | //! coming from:
|
56 | 53 | //!
|
57 | 54 | //! ```
|
|
75 | 72 | //! # }
|
76 | 73 | //! ```
|
77 | 74 | //!
|
78 |
| -//! [seek]: trait.Seek.html |
79 |
| -//! [bufread]: trait.BufRead.html |
80 |
| -//! |
81 |
| -//! `BufRead` uses an internal buffer to provide a number of other ways to read, but |
| 75 | +//! [`BufRead`] uses an internal buffer to provide a number of other ways to read, but |
82 | 76 | //! to show it off, we'll need to talk about buffers in general. Keep reading!
|
83 | 77 | //!
|
84 | 78 | //! ## BufReader and BufWriter
|
85 | 79 | //!
|
86 | 80 | //! Byte-based interfaces are unwieldy and can be inefficient, as we'd need to be
|
87 | 81 | //! making near-constant calls to the operating system. To help with this,
|
88 |
| -//! `std::io` comes with two structs, `BufReader` and `BufWriter`, which wrap |
| 82 | +//! `std::io` comes with two structs, [`BufReader`] and [`BufWriter`], which wrap |
89 | 83 | //! readers and writers. The wrapper uses a buffer, reducing the number of
|
90 | 84 | //! calls and providing nicer methods for accessing exactly what you want.
|
91 | 85 | //!
|
92 |
| -//! For example, `BufReader` works with the `BufRead` trait to add extra |
| 86 | +//! For example, [`BufReader`] works with the [`BufRead`] trait to add extra |
93 | 87 | //! methods to any reader:
|
94 | 88 | //!
|
95 | 89 | //! ```
|
|
111 | 105 | //! # }
|
112 | 106 | //! ```
|
113 | 107 | //!
|
114 |
| -//! `BufWriter` doesn't add any new ways of writing; it just buffers every call |
115 |
| -//! to [`write()`][write()]: |
| 108 | +//! [`BufWriter`] doesn't add any new ways of writing; it just buffers every call |
| 109 | +//! to [`write()`]: |
116 | 110 | //!
|
117 | 111 | //! ```
|
118 | 112 | //! use std::io;
|
|
134 | 128 | //! # }
|
135 | 129 | //! ```
|
136 | 130 | //!
|
137 |
| -//! [write()]: trait.Write.html#tymethod.write |
138 |
| -//! |
139 | 131 | //! ## Standard input and output
|
140 | 132 | //!
|
141 | 133 | //! A very common source of input is standard input:
|
|
165 | 157 | //! # }
|
166 | 158 | //! ```
|
167 | 159 | //!
|
168 |
| -//! Of course, using `io::stdout()` directly is less common than something like |
169 |
| -//! `println!`. |
| 160 | +//! Of course, using [`io::stdout()`] directly is less common than something like |
| 161 | +//! [`println!`]. |
170 | 162 | //!
|
171 | 163 | //! ## Iterator types
|
172 | 164 | //!
|
173 | 165 | //! A large number of the structures provided by `std::io` are for various
|
174 |
| -//! ways of iterating over I/O. For example, `Lines` is used to split over |
| 166 | +//! ways of iterating over I/O. For example, [`Lines`] is used to split over |
175 | 167 | //! lines:
|
176 | 168 | //!
|
177 | 169 | //! ```
|
|
211 | 203 | //!
|
212 | 204 | //! ## io::Result
|
213 | 205 | //!
|
214 |
| -//! Last, but certainly not least, is [`io::Result`][result]. This type is used |
| 206 | +//! Last, but certainly not least, is [`io::Result`]. This type is used |
215 | 207 | //! as the return type of many `std::io` functions that can cause an error, and
|
216 | 208 | //! can be returned from your own functions as well. Many of the examples in this
|
217 |
| -//! module use the [`try!`][try] macro: |
| 209 | +//! module use the [`try!`] macro: |
218 | 210 | //!
|
219 | 211 | //! ```
|
220 | 212 | //! use std::io;
|
|
230 | 222 | //! }
|
231 | 223 | //! ```
|
232 | 224 | //!
|
233 |
| -//! The return type of `read_input()`, `io::Result<()>`, is a very common type |
234 |
| -//! for functions which don't have a 'real' return value, but do want to return |
235 |
| -//! errors if they happen. In this case, the only purpose of this function is |
| 225 | +//! The return type of `read_input()`, [`io::Result<()>`][`io::Result`], is a very |
| 226 | +//! common type for functions which don't have a 'real' return value, but do want to |
| 227 | +//! return errors if they happen. In this case, the only purpose of this function is |
236 | 228 | //! to read the line and print it, so we use `()`.
|
237 | 229 | //!
|
238 |
| -//! [result]: type.Result.html |
239 |
| -//! [try]: ../macro.try.html |
240 |
| -//! |
241 | 230 | //! ## Platform-specific behavior
|
242 | 231 | //!
|
243 | 232 | //! Many I/O functions throughout the standard library are documented to indicate
|
|
246 | 235 | //! any possibly unclear semantics. Note, however, that this is informative, not a binding
|
247 | 236 | //! contract. The implementation of many of these functions are subject to change over
|
248 | 237 | //! time and may call fewer or more syscalls/library functions.
|
| 238 | +//! |
| 239 | +//! [`Read`]: trait.Read.html |
| 240 | +//! [`Write`]: trait.Write.html |
| 241 | +//! [`Seek`]: trait.Seek.html |
| 242 | +//! [`BufRead`]: trait.BufRead.html |
| 243 | +//! [`File`]: ../fs/struct.File.html |
| 244 | +//! [`TcpStream`]: ../net/struct.TcpStream.html |
| 245 | +//! [`Vec<T>`]: ../vec/struct.Vec.html |
| 246 | +//! [`BufReader`]: struct.BufReader.html |
| 247 | +//! [`BufWriter`]: struct.BufWriter.html |
| 248 | +//! [`write()`]: trait.Write.html#tymethod.write |
| 249 | +//! [`io::stdout()`]: fn.stdout.html |
| 250 | +//! [`println!`]: ../macro.println.html |
| 251 | +//! [`Lines`]: struct.Lines.html |
| 252 | +//! [`io::Result`]: type.Result.html |
| 253 | +//! [`try!`]: ../macro.try.html |
249 | 254 |
|
250 | 255 | #![stable(feature = "rust1", since = "1.0.0")]
|
251 | 256 |
|
|
0 commit comments