mirror of https://github.com/rust-lang/book
Fix up even more links in the first edition.
This commit is contained in:
parent
bd8d27beb5
commit
23a7a7bdb6
|
@ -3,8 +3,8 @@
|
|||
The [`Borrow`][borrow] and [`AsRef`][asref] traits are very similar, but
|
||||
different. Here’s a quick refresher on what these two traits mean.
|
||||
|
||||
[borrow]: ../std/borrow/trait.Borrow.html
|
||||
[asref]: ../std/convert/trait.AsRef.html
|
||||
[borrow]: ../../std/borrow/trait.Borrow.html
|
||||
[asref]: ../../std/convert/trait.AsRef.html
|
||||
|
||||
# Borrow
|
||||
|
||||
|
@ -19,8 +19,8 @@ fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V>
|
|||
Q: Hash + Eq
|
||||
```
|
||||
|
||||
[hashmap]: ../std/collections/struct.HashMap.html
|
||||
[get]: ../std/collections/struct.HashMap.html#method.get
|
||||
[hashmap]: ../../std/collections/struct.HashMap.html
|
||||
[get]: ../../std/collections/struct.HashMap.html#method.get
|
||||
|
||||
This signature is pretty complicated. The `K` parameter is what we’re interested
|
||||
in here. It refers to a parameter of the `HashMap` itself:
|
||||
|
|
|
@ -38,7 +38,7 @@ This is a zero-cost abstraction for dynamic allocation. If you want to allocate
|
|||
heap and safely pass around a pointer to that memory, this is ideal. Note that you will only be
|
||||
allowed to share references to this by the regular borrowing rules, checked at compile time.
|
||||
|
||||
[box]: ../std/boxed/struct.Box.html
|
||||
[box]: ../../std/boxed/struct.Box.html
|
||||
|
||||
## `&T` and `&mut T`
|
||||
|
||||
|
@ -104,7 +104,7 @@ two `usize` values) as compared to a regular `Box<T>` (for "strong" and "weak" r
|
|||
or goes out of scope respectively. Note that a clone will not do a deep copy, rather it will simply
|
||||
increment the inner reference count and return a copy of the `Rc<T>`.
|
||||
|
||||
[rc]: ../std/rc/struct.Rc.html
|
||||
[rc]: ../../std/rc/struct.Rc.html
|
||||
|
||||
# Cell types
|
||||
|
||||
|
@ -234,9 +234,9 @@ indicator (one word in size) along with the data.
|
|||
|
||||
At runtime each borrow causes a modification/check of the refcount.
|
||||
|
||||
[cell-mod]: ../std/cell/index.html
|
||||
[cell]: ../std/cell/struct.Cell.html
|
||||
[refcell]: ../std/cell/struct.RefCell.html
|
||||
[cell-mod]: ../../std/cell/index.html
|
||||
[cell]: ../../std/cell/struct.Cell.html
|
||||
[refcell]: ../../std/cell/struct.RefCell.html
|
||||
|
||||
# Synchronous types
|
||||
|
||||
|
@ -252,7 +252,7 @@ time.
|
|||
There are many useful wrappers for concurrent programming in the [sync][sync] module, but only the
|
||||
major ones will be covered below.
|
||||
|
||||
[sync]: ../std/sync/index.html
|
||||
[sync]: ../../std/sync/index.html
|
||||
|
||||
## `Arc<T>`
|
||||
|
||||
|
@ -280,7 +280,7 @@ This has the added cost of using atomics for changing the refcount (which will h
|
|||
cloned or goes out of scope). When sharing data from an `Arc` in a single thread, it is preferable
|
||||
to share `&` pointers whenever possible.
|
||||
|
||||
[arc]: ../std/sync/struct.Arc.html
|
||||
[arc]: ../../std/sync/struct.Arc.html
|
||||
|
||||
## `Mutex<T>` and `RwLock<T>`
|
||||
|
||||
|
@ -316,8 +316,8 @@ These use internal atomic-like types to maintain the locks, which are pretty cos
|
|||
all memory reads across processors till they're done). Waiting on these locks can also be slow when
|
||||
there's a lot of concurrent access happening.
|
||||
|
||||
[rwlock]: ../std/sync/struct.RwLock.html
|
||||
[mutex]: ../std/sync/struct.Mutex.html
|
||||
[rwlock]: ../../std/sync/struct.RwLock.html
|
||||
[mutex]: ../../std/sync/struct.Mutex.html
|
||||
[sessions]: https://github.com/Munksgaard/rust-sessions
|
||||
|
||||
# Composition
|
||||
|
|
|
@ -26,7 +26,7 @@ to help us make sense of code that can possibly be concurrent.
|
|||
### `Send`
|
||||
|
||||
The first trait we're going to talk about is
|
||||
[`Send`](../std/marker/trait.Send.html). When a type `T` implements `Send`, it
|
||||
[`Send`](../../std/marker/trait.Send.html). When a type `T` implements `Send`, it
|
||||
indicates that something of this type is able to have ownership transferred
|
||||
safely between threads.
|
||||
|
||||
|
@ -43,7 +43,7 @@ us enforce that it can't leave the current thread.
|
|||
|
||||
### `Sync`
|
||||
|
||||
The second of these traits is called [`Sync`](../std/marker/trait.Sync.html).
|
||||
The second of these traits is called [`Sync`](../../std/marker/trait.Sync.html).
|
||||
When a type `T` implements `Sync`, it indicates that something
|
||||
of this type has no possibility of introducing memory unsafety when used from
|
||||
multiple threads concurrently through shared references. This implies that
|
||||
|
@ -333,8 +333,8 @@ locked, it will wait until the other thread releases the lock.
|
|||
The lock "release" here is implicit; when the result of the lock (in this case,
|
||||
`data`) goes out of scope, the lock is automatically released.
|
||||
|
||||
Note that [`lock`](../std/sync/struct.Mutex.html#method.lock) method of
|
||||
[`Mutex`](../std/sync/struct.Mutex.html) has this signature:
|
||||
Note that [`lock`](../../std/sync/struct.Mutex.html#method.lock) method of
|
||||
[`Mutex`](../../std/sync/struct.Mutex.html) has this signature:
|
||||
|
||||
```rust,ignore
|
||||
fn lock(&self) -> LockResult<MutexGuard<T>>
|
||||
|
|
|
@ -1113,7 +1113,7 @@ The first two are a result of `Error` requiring impls for both `Debug` and
|
|||
`Display`. The latter two are from the two methods defined on `Error`. The
|
||||
power of `Error` comes from the fact that all error types impl `Error`, which
|
||||
means errors can be existentially quantified as a
|
||||
[trait object](../book/trait-objects.html).
|
||||
[trait object](../book/first-edition/trait-objects.html).
|
||||
This manifests as either `Box<Error>` or `&Error`. Indeed, the `cause` method
|
||||
returns an `&Error`, which is itself a trait object. We'll revisit the
|
||||
`Error` trait's utility as a trait object later.
|
||||
|
@ -1189,7 +1189,7 @@ different error types and satisfy the contracts defined for `description` and
|
|||
|
||||
The `std::convert::From` trait is
|
||||
[defined in the standard
|
||||
library](../std/convert/trait.From.html):
|
||||
library](../../std/convert/trait.From.html):
|
||||
|
||||
<span id="code-from-def"></span>
|
||||
|
||||
|
@ -1204,7 +1204,7 @@ way to talk about conversion *from* a particular type `T` to some other type
|
|||
(in this case, “some other type” is the subject of the impl, or `Self`).
|
||||
The crux of `From` is the
|
||||
[set of implementations provided by the standard
|
||||
library](../std/convert/trait.From.html).
|
||||
library](../../std/convert/trait.From.html).
|
||||
|
||||
Here are a few simple examples demonstrating how `From` works:
|
||||
|
||||
|
@ -1271,7 +1271,7 @@ macro_rules! try {
|
|||
```
|
||||
|
||||
This is not its real definition. Its real definition is
|
||||
[in the standard library](../std/macro.try.html):
|
||||
[in the standard library](../../std/macro.try.html):
|
||||
|
||||
<span id="code-try-def"></span>
|
||||
|
||||
|
@ -1340,8 +1340,8 @@ There's one little nit left: the `Box<Error>` type is *opaque*. If we
|
|||
return a `Box<Error>` to the caller, the caller can't (easily) inspect
|
||||
underlying error type. The situation is certainly better than `String`
|
||||
because the caller can call methods like
|
||||
[`description`](../std/error/trait.Error.html#tymethod.description)
|
||||
and [`cause`](../std/error/trait.Error.html#method.cause), but the
|
||||
[`description`](../../std/error/trait.Error.html#tymethod.description)
|
||||
and [`cause`](../../std/error/trait.Error.html#method.cause), but the
|
||||
limitation remains: `Box<Error>` is opaque. (N.B. This isn't entirely
|
||||
true because Rust does have runtime reflection, which is useful in
|
||||
some scenarios that are [beyond the scope of this
|
||||
|
@ -1484,14 +1484,14 @@ And that's it!
|
|||
If your library needs to report custom errors, then you should
|
||||
probably define your own error type. It's up to you whether or not to
|
||||
expose its representation (like
|
||||
[`ErrorKind`](../std/io/enum.ErrorKind.html)) or keep it hidden (like
|
||||
[`ParseIntError`](../std/num/struct.ParseIntError.html)). Regardless
|
||||
[`ErrorKind`](../../std/io/enum.ErrorKind.html)) or keep it hidden (like
|
||||
[`ParseIntError`](../../std/num/struct.ParseIntError.html)). Regardless
|
||||
of how you do it, it's usually good practice to at least provide some
|
||||
information about the error beyond its `String`
|
||||
representation. But certainly, this will vary depending on use cases.
|
||||
|
||||
At a minimum, you should probably implement the
|
||||
[`Error`](../std/error/trait.Error.html)
|
||||
[`Error`](../../std/error/trait.Error.html)
|
||||
trait. This will give users of your library some minimum flexibility for
|
||||
[composing errors](#the-real-try-macro). Implementing the `Error` trait also
|
||||
means that users are guaranteed the ability to obtain a string representation
|
||||
|
@ -1507,8 +1507,8 @@ provides `From` impls for both `io::Error` and `byteorder::Error`.
|
|||
Finally, depending on your tastes, you may also want to define a
|
||||
[`Result` type alias](#the-result-type-alias-idiom), particularly if your
|
||||
library defines a single error type. This is used in the standard library
|
||||
for [`io::Result`](../std/io/type.Result.html)
|
||||
and [`fmt::Result`](../std/fmt/type.Result.html).
|
||||
for [`io::Result`](../../std/io/type.Result.html)
|
||||
and [`fmt::Result`](../../std/fmt/type.Result.html).
|
||||
|
||||
# Case study: A program to read population data
|
||||
|
||||
|
@ -1702,9 +1702,9 @@ fn main() {
|
|||
Let's outline the errors. We can start with the obvious: the three places that
|
||||
`unwrap` is called:
|
||||
|
||||
1. [`File::open`](../std/fs/struct.File.html#method.open)
|
||||
1. [`File::open`](../../std/fs/struct.File.html#method.open)
|
||||
can return an
|
||||
[`io::Error`](../std/io/struct.Error.html).
|
||||
[`io::Error`](../../std/io/struct.Error.html).
|
||||
2. [`csv::Reader::decode`](http://burntsushi.net/rustdoc/csv/struct.Reader.html#method.decode)
|
||||
decodes one record at a time, and
|
||||
[decoding a
|
||||
|
@ -1859,7 +1859,7 @@ Instead of `x.unwrap()`, we now have `try!(x)`. Since our function returns a
|
|||
error occurs.
|
||||
|
||||
At the end of `search` we also convert a plain string to an error type
|
||||
by using the [corresponding `From` impls](../std/convert/trait.From.html):
|
||||
by using the [corresponding `From` impls](../../std/convert/trait.From.html):
|
||||
|
||||
```rust,ignore
|
||||
// We are making use of this impl in the code above, since we call `From::from`
|
||||
|
@ -2162,10 +2162,10 @@ heuristics!
|
|||
|
||||
* If you're writing short example code that would be overburdened by error
|
||||
handling, it's probably fine to use `unwrap` (whether that's
|
||||
[`Result::unwrap`](../std/result/enum.Result.html#method.unwrap),
|
||||
[`Option::unwrap`](../std/option/enum.Option.html#method.unwrap)
|
||||
[`Result::unwrap`](../../std/result/enum.Result.html#method.unwrap),
|
||||
[`Option::unwrap`](../../std/option/enum.Option.html#method.unwrap)
|
||||
or preferably
|
||||
[`Option::expect`](../std/option/enum.Option.html#method.expect)).
|
||||
[`Option::expect`](../../std/option/enum.Option.html#method.expect)).
|
||||
Consumers of your code should know to use proper error handling. (If they
|
||||
don't, send them here!)
|
||||
* If you're writing a quick 'n' dirty program, don't feel ashamed if you use
|
||||
|
@ -2175,37 +2175,37 @@ heuristics!
|
|||
anyway, then use either a `String` or a `Box<Error>` for your
|
||||
error type.
|
||||
* Otherwise, in a program, define your own error types with appropriate
|
||||
[`From`](../std/convert/trait.From.html)
|
||||
[`From`](../../std/convert/trait.From.html)
|
||||
and
|
||||
[`Error`](../std/error/trait.Error.html)
|
||||
impls to make the [`try!`](../std/macro.try.html)
|
||||
[`Error`](../../std/error/trait.Error.html)
|
||||
impls to make the [`try!`](../../std/macro.try.html)
|
||||
macro more ergonomic.
|
||||
* If you're writing a library and your code can produce errors, define your own
|
||||
error type and implement the
|
||||
[`std::error::Error`](../std/error/trait.Error.html)
|
||||
[`std::error::Error`](../../std/error/trait.Error.html)
|
||||
trait. Where appropriate, implement
|
||||
[`From`](../std/convert/trait.From.html) to make both
|
||||
[`From`](../../std/convert/trait.From.html) to make both
|
||||
your library code and the caller's code easier to write. (Because of Rust's
|
||||
coherence rules, callers will not be able to impl `From` on your error type,
|
||||
so your library should do it.)
|
||||
* Learn the combinators defined on
|
||||
[`Option`](../std/option/enum.Option.html)
|
||||
[`Option`](../../std/option/enum.Option.html)
|
||||
and
|
||||
[`Result`](../std/result/enum.Result.html).
|
||||
[`Result`](../../std/result/enum.Result.html).
|
||||
Using them exclusively can be a bit tiring at times, but I've personally
|
||||
found a healthy mix of `try!` and combinators to be quite appealing.
|
||||
`and_then`, `map` and `unwrap_or` are my favorites.
|
||||
|
||||
[1]: ../book/patterns.html
|
||||
[2]: ../std/option/enum.Option.html#method.map
|
||||
[3]: ../std/option/enum.Option.html#method.unwrap_or
|
||||
[4]: ../std/option/enum.Option.html#method.unwrap_or_else
|
||||
[5]: ../std/option/enum.Option.html
|
||||
[6]: ../std/result/index.html
|
||||
[7]: ../std/result/enum.Result.html#method.unwrap
|
||||
[8]: ../std/fmt/trait.Debug.html
|
||||
[9]: ../std/primitive.str.html#method.parse
|
||||
[10]: ../book/associated-types.html
|
||||
[1]: ../book/first-edition/patterns.html
|
||||
[2]: ../../std/option/enum.Option.html#method.map
|
||||
[3]: ../../std/option/enum.Option.html#method.unwrap_or
|
||||
[4]: ../../std/option/enum.Option.html#method.unwrap_or_else
|
||||
[5]: ../../std/option/enum.Option.html
|
||||
[6]: ../../std/result/index.html
|
||||
[7]: ../../std/result/enum.Result.html#method.unwrap
|
||||
[8]: ../../std/fmt/trait.Debug.html
|
||||
[9]: ../../std/primitive.str.html#method.parse
|
||||
[10]: ../book/first-edition/associated-types.html
|
||||
[11]: https://github.com/petewarden/dstkdata
|
||||
[12]: http://burntsushi.net/stuff/worldcitiespop.csv.gz
|
||||
[13]: http://burntsushi.net/stuff/uscitiespop.csv.gz
|
||||
|
|
|
@ -246,7 +246,7 @@ Foreign libraries often hand off ownership of resources to the calling code.
|
|||
When this occurs, we must use Rust's destructors to provide safety and guarantee
|
||||
the release of these resources (especially in the case of panic).
|
||||
|
||||
For more about destructors, see the [Drop trait](../std/ops/trait.Drop.html).
|
||||
For more about destructors, see the [Drop trait](../../std/ops/trait.Drop.html).
|
||||
|
||||
# Callbacks from C code to Rust functions
|
||||
|
||||
|
@ -710,7 +710,7 @@ Please note that [`catch_unwind()`] will only catch unwinding panics, not
|
|||
those who abort the process. See the documentation of [`catch_unwind()`]
|
||||
for more information.
|
||||
|
||||
[`catch_unwind()`]: ../std/panic/fn.catch_unwind.html
|
||||
[`catch_unwind()`]: ../../std/panic/fn.catch_unwind.html
|
||||
|
||||
# Representing opaque structs
|
||||
|
||||
|
|
|
@ -186,5 +186,5 @@ functions or methods. See [Iterators § Consumers](iterators.html#consumers)
|
|||
for an example.
|
||||
|
||||
[traits]: traits.html
|
||||
[Vec]: ../std/vec/struct.Vec.html
|
||||
[turbofish]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.collect
|
||||
[Vec]: ../../std/vec/struct.Vec.html
|
||||
[turbofish]: ../../std/iter/trait.Iterator.html#method.collect
|
||||
|
|
|
@ -56,7 +56,7 @@ They can be used to manage control flow in a modular fashion.
|
|||
|
||||
A type without a statically known size or alignment. ([more info][link])
|
||||
|
||||
[link]: ../nomicon/exotic-sizes.html#dynamically-sized-types-dsts
|
||||
[link]: ../../nomicon/exotic-sizes.html#dynamically-sized-types-dsts
|
||||
|
||||
### Expression
|
||||
|
||||
|
|
|
@ -106,8 +106,8 @@ prelude, you’ll have to `use` it directly. There is also a second ‘prelude
|
|||
[`io` prelude][ioprelude], which serves a similar function: you import it, and it
|
||||
imports a number of useful, `io`-related things.
|
||||
|
||||
[prelude]: ../std/prelude/index.html
|
||||
[ioprelude]: ../std/io/prelude/index.html
|
||||
[prelude]: ../../std/prelude/index.html
|
||||
[ioprelude]: ../../std/io/prelude/index.html
|
||||
|
||||
```rust,ignore
|
||||
fn main() {
|
||||
|
@ -177,7 +177,7 @@ bound to: `String::new()`.
|
|||
`String` is a string type, provided by the standard library. A
|
||||
[`String`][string] is a growable, UTF-8 encoded bit of text.
|
||||
|
||||
[string]: ../std/string/struct.String.html
|
||||
[string]: ../../std/string/struct.String.html
|
||||
|
||||
The `::new()` syntax uses `::` because this is an ‘associated function’ of
|
||||
a particular type. That is to say, it’s associated with `String` itself,
|
||||
|
@ -209,7 +209,7 @@ have written this line as `std::io::stdin()`.
|
|||
This particular function returns a handle to the standard input for your
|
||||
terminal. More specifically, a [std::io::Stdin][iostdin].
|
||||
|
||||
[iostdin]: ../std/io/struct.Stdin.html
|
||||
[iostdin]: ../../std/io/struct.Stdin.html
|
||||
|
||||
The next part will use this handle to get input from the user:
|
||||
|
||||
|
@ -222,7 +222,7 @@ Here, we call the [`read_line()`][read_line] method on our handle.
|
|||
particular instance of a type, rather than the type itself. We’re also passing
|
||||
one argument to `read_line()`: `&mut guess`.
|
||||
|
||||
[read_line]: ../std/io/struct.Stdin.html#method.read_line
|
||||
[read_line]: ../../std/io/struct.Stdin.html#method.read_line
|
||||
[method]: method-syntax.html
|
||||
|
||||
Remember how we bound `guess` above? We said it was mutable. However,
|
||||
|
@ -266,8 +266,8 @@ String` we pass it. But it also returns a value: in this case, an
|
|||
standard library: a generic [`Result`][result], and then specific versions for
|
||||
sub-libraries, like `io::Result`.
|
||||
|
||||
[ioresult]: ../std/io/type.Result.html
|
||||
[result]: ../std/result/enum.Result.html
|
||||
[ioresult]: ../../std/io/type.Result.html
|
||||
[result]: ../../std/result/enum.Result.html
|
||||
|
||||
The purpose of these `Result` types is to encode error handling information.
|
||||
Values of the `Result` type, like any type, have methods defined on them. In
|
||||
|
@ -276,7 +276,7 @@ it’s called on, and if it isn’t a successful one, [`panic!`][panic]s with a
|
|||
message you passed it. A `panic!` like this will cause our program to crash,
|
||||
displaying the message.
|
||||
|
||||
[expect]: ../std/result/enum.Result.html#method.expect
|
||||
[expect]: ../../std/result/enum.Result.html#method.expect
|
||||
[panic]: error-handling.html
|
||||
|
||||
If we do not call `expect()`, our program will compile, but
|
||||
|
@ -620,7 +620,7 @@ match guess.cmp(&secret_number) {
|
|||
}
|
||||
```
|
||||
|
||||
[ordering]: ../std/cmp/enum.Ordering.html
|
||||
[ordering]: ../../std/cmp/enum.Ordering.html
|
||||
|
||||
If it’s `Less`, we print `Too small!`, if it’s `Greater`, `Too big!`, and if
|
||||
`Equal`, `You win!`. `match` is really useful, and is used often in Rust.
|
||||
|
@ -726,7 +726,7 @@ exact type of number we want. Hence, `let guess: u32`. The colon (`:`) after
|
|||
thirty-two bit integer. Rust has [a number of built-in number types][number],
|
||||
but we’ve chosen `u32`. It’s a good default choice for a small positive number.
|
||||
|
||||
[parse]: ../std/primitive.str.html#method.parse
|
||||
[parse]: ../../std/primitive.str.html#method.parse
|
||||
[number]: primitive-types.html#numeric-types
|
||||
|
||||
Just like `read_line()`, our call to `parse()` could cause an error. What if
|
||||
|
|
|
@ -341,4 +341,4 @@ can help you with. There are a number of really useful iterators, and you can
|
|||
write your own as well. Iterators provide a safe, efficient way to manipulate
|
||||
all kinds of lists. They're a little unusual at first, but if you play with
|
||||
them, you'll get hooked. For a full list of the different iterators and
|
||||
consumers, check out the [iterator module documentation](../std/iter/index.html).
|
||||
consumers, check out the [iterator module documentation](../../std/iter/index.html).
|
||||
|
|
|
@ -88,7 +88,7 @@ the iterator, and we loop another time. When there are no more values, the `for`
|
|||
loop is over.
|
||||
|
||||
[iterator]: iterators.html
|
||||
[`IntoIterator`]: ../std/iter/trait.IntoIterator.html
|
||||
[`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
|
||||
|
||||
In our example, `0..10` is an expression that takes a start and an end position,
|
||||
and gives an iterator over those values. The upper bound is exclusive, though,
|
||||
|
|
|
@ -101,7 +101,7 @@ trees, at compile time. The semicolon is optional on the last (here, only)
|
|||
case. The "pattern" on the left-hand side of `=>` is known as a ‘matcher’.
|
||||
These have [their own little grammar] within the language.
|
||||
|
||||
[their own little grammar]: ../reference/macros.html
|
||||
[their own little grammar]: ../../reference/macros.html
|
||||
|
||||
The matcher `$x:expr` will match any Rust expression, binding that syntax tree
|
||||
to the ‘metavariable’ `$x`. The identifier `expr` is a ‘fragment specifier’;
|
||||
|
@ -363,7 +363,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
[items]: ../reference/items.html
|
||||
[items]: ../../reference/items.html
|
||||
|
||||
# Recursive macros
|
||||
|
||||
|
@ -490,7 +490,7 @@ be forced to choose between parsing `$i` and parsing `$e`. Changing the
|
|||
invocation syntax to put a distinctive token in front can solve the problem. In
|
||||
this case, you can write `$(I $i:ident)* E $e:expr`.
|
||||
|
||||
[item]: ../reference/items.html
|
||||
[item]: ../../reference/items.html
|
||||
|
||||
# Scoping and macro import/export
|
||||
|
||||
|
@ -565,7 +565,7 @@ When this library is loaded with `#[macro_use] extern crate`, only `m2` will
|
|||
be imported.
|
||||
|
||||
The Rust Reference has a [listing of macro-related
|
||||
attributes](../reference/attributes.html#macro-related-attributes).
|
||||
attributes](../../reference/attributes.html#macro-related-attributes).
|
||||
|
||||
# The variable `$crate`
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ let x = Arc::new(5);
|
|||
let y = x.clone();
|
||||
```
|
||||
|
||||
[arc]: ../std/sync/struct.Arc.html
|
||||
[arc]: ../../std/sync/struct.Arc.html
|
||||
|
||||
When we call `clone()`, the `Arc<T>` needs to update the reference count. Yet
|
||||
we’ve not used any `mut`s here, `x` is an immutable binding, and we didn’t take
|
||||
|
@ -107,7 +107,7 @@ let x = RefCell::new(42);
|
|||
let y = x.borrow_mut();
|
||||
```
|
||||
|
||||
[stdcell]: ../std/cell/index.html
|
||||
[stdcell]: ../../std/cell/index.html
|
||||
|
||||
RefCell hands out `&mut` references to what’s inside of it with the
|
||||
`borrow_mut()` method. Isn’t that dangerous? What if we do:
|
||||
|
@ -176,6 +176,6 @@ point.y.set(7);
|
|||
println!("y: {:?}", point.y);
|
||||
```
|
||||
|
||||
[cell]: ../std/cell/struct.Cell.html
|
||||
[cell]: ../../std/cell/struct.Cell.html
|
||||
|
||||
This will print `y: Cell { value: 7 }`. We’ve successfully updated `y`.
|
||||
|
|
|
@ -41,7 +41,7 @@ There are a number of operators that can be overloaded this way, and all of
|
|||
their associated traits live in the [`std::ops`][stdops] module. Check out its
|
||||
documentation for the full list.
|
||||
|
||||
[stdops]: ../std/ops/index.html
|
||||
[stdops]: ../../std/ops/index.html
|
||||
|
||||
Implementing these traits follows a pattern. Let’s look at [`Add`][add] in more
|
||||
detail:
|
||||
|
@ -56,7 +56,7 @@ pub trait Add<RHS = Self> {
|
|||
# }
|
||||
```
|
||||
|
||||
[add]: ../std/ops/trait.Add.html
|
||||
[add]: ../../std/ops/trait.Add.html
|
||||
|
||||
There’s three types in total involved here: the type you `impl Add` for, `RHS`,
|
||||
which defaults to `Self`, and `Output`. For an expression `let z = x + y`, `x`
|
||||
|
|
|
@ -22,7 +22,7 @@ A common use of booleans is in [`if` conditionals][if].
|
|||
You can find more documentation for `bool`s [in the standard library
|
||||
documentation][bool].
|
||||
|
||||
[bool]: ../std/primitive.bool.html
|
||||
[bool]: ../../std/primitive.bool.html
|
||||
|
||||
# `char`
|
||||
|
||||
|
@ -40,7 +40,7 @@ but four.
|
|||
You can find more documentation for `char`s [in the standard library
|
||||
documentation][char].
|
||||
|
||||
[char]: ../std/primitive.char.html
|
||||
[char]: ../../std/primitive.char.html
|
||||
|
||||
# Numeric types
|
||||
|
||||
|
@ -62,18 +62,18 @@ let y = 1.0; // `y` has type `f64`.
|
|||
Here’s a list of the different numeric types, with links to their documentation
|
||||
in the standard library:
|
||||
|
||||
* [i8](../std/primitive.i8.html)
|
||||
* [i16](../std/primitive.i16.html)
|
||||
* [i32](../std/primitive.i32.html)
|
||||
* [i64](../std/primitive.i64.html)
|
||||
* [u8](../std/primitive.u8.html)
|
||||
* [u16](../std/primitive.u16.html)
|
||||
* [u32](../std/primitive.u32.html)
|
||||
* [u64](../std/primitive.u64.html)
|
||||
* [isize](../std/primitive.isize.html)
|
||||
* [usize](../std/primitive.usize.html)
|
||||
* [f32](../std/primitive.f32.html)
|
||||
* [f64](../std/primitive.f64.html)
|
||||
* [i8](../../std/primitive.i8.html)
|
||||
* [i16](../../std/primitive.i16.html)
|
||||
* [i32](../../std/primitive.i32.html)
|
||||
* [i64](../../std/primitive.i64.html)
|
||||
* [u8](../../std/primitive.u8.html)
|
||||
* [u16](../../std/primitive.u16.html)
|
||||
* [u32](../../std/primitive.u32.html)
|
||||
* [u64](../../std/primitive.u64.html)
|
||||
* [isize](../../std/primitive.isize.html)
|
||||
* [usize](../../std/primitive.usize.html)
|
||||
* [f32](../../std/primitive.f32.html)
|
||||
* [f64](../../std/primitive.f64.html)
|
||||
|
||||
Let’s go over them by category:
|
||||
|
||||
|
@ -155,7 +155,7 @@ languages.
|
|||
You can find more documentation for `array`s [in the standard library
|
||||
documentation][array].
|
||||
|
||||
[array]: ../std/primitive.array.html
|
||||
[array]: ../../std/primitive.array.html
|
||||
|
||||
# Slices
|
||||
|
||||
|
@ -189,7 +189,7 @@ Slices have type `&[T]`. We’ll talk about that `T` when we cover
|
|||
You can find more documentation for slices [in the standard library
|
||||
documentation][slice].
|
||||
|
||||
[slice]: ../std/primitive.slice.html
|
||||
[slice]: ../../std/primitive.slice.html
|
||||
|
||||
# `str`
|
||||
|
||||
|
@ -205,7 +205,7 @@ reference, like `&str`. We'll elaborate further when we cover
|
|||
You can find more documentation for `str` [in the standard library
|
||||
documentation][str].
|
||||
|
||||
[str]: ../std/primitive.str.html
|
||||
[str]: ../../std/primitive.str.html
|
||||
|
||||
# Tuples
|
||||
|
||||
|
@ -289,7 +289,7 @@ Like array indexing, it starts at zero, but unlike array indexing, it uses a
|
|||
You can find more documentation for tuples [in the standard library
|
||||
documentation][tuple].
|
||||
|
||||
[tuple]: ../std/primitive.tuple.html
|
||||
[tuple]: ../../std/primitive.tuple.html
|
||||
|
||||
# Functions
|
||||
|
||||
|
|
|
@ -72,7 +72,7 @@ println!("raw points at {}", points_at);
|
|||
For more operations on raw pointers, see [their API documentation][rawapi].
|
||||
|
||||
[unsafe]: unsafe.html
|
||||
[rawapi]: ../std/primitive.pointer.html
|
||||
[rawapi]: ../../std/primitive.pointer.html
|
||||
|
||||
# FFI
|
||||
|
||||
|
|
|
@ -192,4 +192,4 @@ feature called ‘[`Deref` coercions][dc]’.
|
|||
|
||||
[ut]: unsized-types.html
|
||||
[dc]: deref-coercions.html
|
||||
[connect]: ../std/net/struct.TcpStream.html#method.connect
|
||||
[connect]: ../../std/net/struct.TcpStream.html#method.connect
|
||||
|
|
|
@ -235,10 +235,10 @@
|
|||
[Primitive Types (Tuple Indexing)]: primitive-types.html#tuple-indexing
|
||||
[Primitive Types (Tuples)]: primitive-types.html#tuples
|
||||
[Raw Pointers]: raw-pointers.html
|
||||
[Reference (Byte String Literals)]: ../reference/tokens.html/#byte-string-literals
|
||||
[Reference (Integer literals)]: ../reference/tokens.html#integer-literals
|
||||
[Reference (Raw Byte String Literals)]: ../reference/tokens.html#raw-byte-string-literals
|
||||
[Reference (Raw String Literals)]: ../reference/tokens.html#raw-string-literals
|
||||
[Reference (Byte String Literals)]: ../../reference/tokens.html/#byte-string-literals
|
||||
[Reference (Integer literals)]: ../../reference/tokens.html#integer-literals
|
||||
[Reference (Raw Byte String Literals)]: ../../reference/tokens.html#raw-byte-string-literals
|
||||
[Reference (Raw String Literals)]: ../../reference/tokens.html#raw-string-literals
|
||||
[References and Borrowing]: references-and-borrowing.html
|
||||
[Strings]: strings.html
|
||||
[Structs (Update syntax)]: structs.html#update-syntax
|
||||
|
|
|
@ -215,7 +215,7 @@ fn main() {
|
|||
}
|
||||
```
|
||||
|
||||
[box]: ../std/boxed/index.html
|
||||
[box]: ../../std/boxed/index.html
|
||||
|
||||
Here’s what happens in memory when `main()` is called:
|
||||
|
||||
|
|
|
@ -195,7 +195,7 @@ pub struct TraitObject {
|
|||
# }
|
||||
```
|
||||
|
||||
[stdraw]: ../std/raw/struct.TraitObject.html
|
||||
[stdraw]: ../../std/raw/struct.TraitObject.html
|
||||
|
||||
That is, a trait object like `&Foo` consists of a ‘data’ pointer and a ‘vtable’
|
||||
pointer.
|
||||
|
|
|
@ -230,7 +230,7 @@ impl<T: PartialEq> Rectangle<T> { ... }
|
|||
Now, a rectangle can be defined in terms of any type that can be compared for
|
||||
equality.
|
||||
|
||||
[PartialEq]: ../core/cmp/trait.PartialEq.html
|
||||
[PartialEq]: ../../core/cmp/trait.PartialEq.html
|
||||
|
||||
Here we defined a new struct `Rectangle` that accepts numbers of any
|
||||
precision—really, objects of pretty much any type—as long as they can be
|
||||
|
@ -266,7 +266,7 @@ example: the standard library provides a [`Write`][write] trait which adds
|
|||
extra functionality to `File`s, for doing file I/O. By default, a `File`
|
||||
won’t have its methods:
|
||||
|
||||
[write]: ../std/io/trait.Write.html
|
||||
[write]: ../../std/io/trait.Write.html
|
||||
|
||||
```rust,ignore
|
||||
let mut f = std::fs::File::create("foo.txt").expect("Couldn’t create foo.txt");
|
||||
|
@ -540,12 +540,12 @@ fn main() {
|
|||
|
||||
However, deriving is limited to a certain set of traits:
|
||||
|
||||
- [`Clone`](../core/clone/trait.Clone.html)
|
||||
- [`Copy`](../core/marker/trait.Copy.html)
|
||||
- [`Debug`](../core/fmt/trait.Debug.html)
|
||||
- [`Default`](../core/default/trait.Default.html)
|
||||
- [`Eq`](../core/cmp/trait.Eq.html)
|
||||
- [`Hash`](../core/hash/trait.Hash.html)
|
||||
- [`Ord`](../core/cmp/trait.Ord.html)
|
||||
- [`PartialEq`](../core/cmp/trait.PartialEq.html)
|
||||
- [`PartialOrd`](../core/cmp/trait.PartialOrd.html)
|
||||
- [`Clone`](../../core/clone/trait.Clone.html)
|
||||
- [`Copy`](../../core/marker/trait.Copy.html)
|
||||
- [`Debug`](../../core/fmt/trait.Debug.html)
|
||||
- [`Default`](../../core/default/trait.Default.html)
|
||||
- [`Eq`](../../core/cmp/trait.Eq.html)
|
||||
- [`Hash`](../../core/hash/trait.Hash.html)
|
||||
- [`Ord`](../../core/cmp/trait.Ord.html)
|
||||
- [`PartialEq`](../../core/cmp/trait.PartialEq.html)
|
||||
- [`PartialOrd`](../../core/cmp/trait.PartialOrd.html)
|
||||
|
|
|
@ -75,4 +75,4 @@ This creates a specialized version of the `Result` type, which always has a
|
|||
in the standard library to create custom errors for each subsection. For
|
||||
example, [io::Result][ioresult].
|
||||
|
||||
[ioresult]: ../std/io/type.Result.html
|
||||
[ioresult]: ../../std/io/type.Result.html
|
||||
|
|
|
@ -139,4 +139,4 @@ I’ll repeat again: even though you _can_ do arbitrary things in unsafe blocks
|
|||
and functions doesn’t mean you should. The compiler will act as though you’re
|
||||
upholding its invariants, so be careful!
|
||||
|
||||
[intrinsics]: ../unstable-book/intrinsics.html
|
||||
[intrinsics]: ../../unstable-book/intrinsics.html
|
||||
|
|
|
@ -9,7 +9,7 @@ don’t want to use the standard library via an attribute: `#![no_std]`.
|
|||
> Note: This feature is technically stable, but there are some caveats. For
|
||||
> one, you can build a `#![no_std]` _library_ on stable, but not a _binary_.
|
||||
> For details on binaries without the standard library, see [the nightly
|
||||
> chapter on 'lang items'](../unstable-book/lang-items.html#using-libc)
|
||||
> chapter on 'lang items'](../../unstable-book/lang-items.html#using-libc)
|
||||
|
||||
To use `#![no_std]`, add it to your crate root:
|
||||
|
||||
|
@ -22,11 +22,11 @@ fn plus_one(x: i32) -> i32 {
|
|||
```
|
||||
|
||||
Much of the functionality that’s exposed in the standard library is also
|
||||
available via the [`core` crate](../core/index.html). When we’re using the
|
||||
available via the [`core` crate](../../core/index.html). When we’re using the
|
||||
standard library, Rust automatically brings `std` into scope, allowing you to
|
||||
use its features without an explicit import. By the same token, when using
|
||||
`#![no_std]`, Rust will bring `core` into scope for you, as well as [its
|
||||
prelude](../core/prelude/v1/index.html). This means that a lot of code will Just
|
||||
prelude](../../core/prelude/v1/index.html). This means that a lot of code will Just
|
||||
Work:
|
||||
|
||||
```rust,ignore
|
||||
|
|
|
@ -176,7 +176,7 @@ more detailed manner, there are a [wide number of options available][format].
|
|||
For now, we'll stick to the default: integers aren't very complicated to
|
||||
print.
|
||||
|
||||
[format]: ../std/fmt/index.html
|
||||
[format]: ../../std/fmt/index.html
|
||||
|
||||
# Scope and shadowing
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ for i in &v {
|
|||
Vectors have many more useful methods, which you can read about in [their
|
||||
API documentation][vec].
|
||||
|
||||
[vec]: ../std/vec/index.html
|
||||
[box]: ../std/boxed/index.html
|
||||
[vec]: ../../std/vec/index.html
|
||||
[box]: ../../std/boxed/index.html
|
||||
[generic]: generics.html
|
||||
[panic]: concurrency.html#panics
|
||||
[get]: ../std/vec/struct.Vec.html#method.get
|
||||
[get_mut]: ../std/vec/struct.Vec.html#method.get_mut
|
||||
[get]: ../../std/vec/struct.Vec.html#method.get
|
||||
[get_mut]: ../../std/vec/struct.Vec.html#method.get_mut
|
||||
|
|
Loading…
Reference in New Issue