Skip to content

Commit ce7f52b

Browse files
authored
Merge pull request #282 from JohnTitor/reorganize-chapters
Reorganize some chapters
2 parents 2e159b0 + ce7f7f8 commit ce7f52b

24 files changed

+106
-96
lines changed

README.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ order to write correct Unsafe Rust programs. Due to the nature of this problem,
1919
it may lead to unleashing untold horrors that shatter your psyche into a billion
2020
infinitesimal fragments of despair.
2121

22-
### Requirements
22+
## Requirements
2323

2424
Building the Nomicon requires [mdBook]. To get it:
2525

2626
[mdBook]: https://github.com/rust-lang/mdBook
2727

2828
```bash
29-
$ cargo install mdbook
29+
cargo install mdbook
3030
```
3131

3232
### `mdbook` usage
3333

3434
To build the Nomicon use the `build` sub-command:
3535

3636
```bash
37-
$ mdbook build
37+
mdbook build
3838
```
3939

4040
The output will be placed in the `book` subdirectory. To check it out, open the
@@ -43,13 +43,23 @@ build` and it'll open the index page in your default browser (if the process is
4343
successful) just like with `cargo doc --open`:
4444

4545
```bash
46-
$ mdbook build --open
46+
mdbook build --open
4747
```
4848

4949
There is also a `test` sub-command to test all code samples contained in the book:
5050

5151
```bash
52-
$ mdbook test
52+
mdbook test
53+
```
54+
55+
### `linkcheck`
56+
57+
We use the `linkcheck` tool to find broken links.
58+
To run it locally:
59+
60+
```sh
61+
curl -sSLo linkcheck.sh https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh
62+
sh linkcheck.sh --all nomicon
5363
```
5464

5565
## Contributing

book.toml

+24
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,29 @@ description = "The Dark Arts of Advanced and Unsafe Rust Programming"
66
[output.html]
77
git-repository-url = "https://github.com/rust-lang/nomicon"
88

9+
[output.html.redirect]
10+
# Vec-related chapters.
11+
"./vec-alloc.html" = "./vec/vec-alloc.html"
12+
"./vec-dealloc.html" = "./vec/vec-dealloc.html"
13+
"./vec-deref.html" = "./vec/vec-deref.html"
14+
"./vec-drain.html" = "./vec/vec-drain.html"
15+
"./vec-final.html" = "./vec/vec-final.html"
16+
"./vec-insert-remove.html" = "./vec/vec-insert-remove.html"
17+
"./vec-into-iter.html" = "./vec/vec-into-iter.html"
18+
"./vec-layout.html" = "./vec/vec-layout.html"
19+
"./vec-push-pop.html" = "./vec/vec-push-pop.html"
20+
"./vec-raw.html" = "./vec/vec-raw.html"
21+
"./vec-zsts.html" = "./vec/vec-zsts.html"
22+
"./vec.html" = "./vec/vec.html"
23+
24+
# Arc and Mutex related chapters.
25+
"./arc-and-mutex.html" = "./arc-mutex/arc-and-mutex.html"
26+
"./arc-base.html" = "./arc-mutex/arc-base.html"
27+
"./arc-clone.html" = "./arc-mutex/arc-clone.html"
28+
"./arc-drop.html" = "./arc-mutex/arc-drop.html"
29+
"./arc-final.html" = "./arc-mutex/arc-final.html"
30+
"./arc-layout.html" = "./arc-mutex/arc-layout.html"
31+
"./arc.html" = "./arc-mutex/arc.html"
32+
933
[rust]
1034
edition = "2018"

src/README.md

-56
This file was deleted.

src/SUMMARY.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Summary
22

3-
[Introduction](README.md)
3+
[Introduction](intro.md)
44

55
* [Meet Safe and Unsafe](meet-safe-and-unsafe.md)
66
* [How Safe and Unsafe Interact](safe-unsafe-meaning.md)
@@ -42,25 +42,25 @@
4242
* [Races](races.md)
4343
* [Send and Sync](send-and-sync.md)
4444
* [Atomics](atomics.md)
45-
* [Implementing Vec](vec.md)
46-
* [Layout](vec-layout.md)
47-
* [Allocating](vec-alloc.md)
48-
* [Push and Pop](vec-push-pop.md)
49-
* [Deallocating](vec-dealloc.md)
50-
* [Deref](vec-deref.md)
51-
* [Insert and Remove](vec-insert-remove.md)
52-
* [IntoIter](vec-into-iter.md)
53-
* [RawVec](vec-raw.md)
54-
* [Drain](vec-drain.md)
55-
* [Handling Zero-Sized Types](vec-zsts.md)
56-
* [Final Code](vec-final.md)
57-
* [Implementing Arc and Mutex](arc-and-mutex.md)
58-
* [Arc](arc.md)
59-
* [Layout](arc-layout.md)
60-
* [Base Code](arc-base.md)
61-
* [Cloning](arc-clone.md)
62-
* [Dropping](arc-drop.md)
63-
* [Final Code](arc-final.md)
45+
* [Implementing Vec](./vec/vec.md)
46+
* [Layout](./vec/vec-layout.md)
47+
* [Allocating](./vec/vec-alloc.md)
48+
* [Push and Pop](./vec/vec-push-pop.md)
49+
* [Deallocating](./vec/vec-dealloc.md)
50+
* [Deref](./vec/vec-deref.md)
51+
* [Insert and Remove](./vec/vec-insert-remove.md)
52+
* [IntoIter](./vec/vec-into-iter.md)
53+
* [RawVec](./vec/vec-raw.md)
54+
* [Drain](./vec/vec-drain.md)
55+
* [Handling Zero-Sized Types](./vec/vec-zsts.md)
56+
* [Final Code](./vec/vec-final.md)
57+
* [Implementing Arc and Mutex](./arc-mutex/arc-and-mutex.md)
58+
* [Arc](./arc-mutex/arc.md)
59+
* [Layout](./arc-mutex/arc-layout.md)
60+
* [Base Code](./arc-mutex/arc-base.md)
61+
* [Cloning](./arc-mutex/arc-clone.md)
62+
* [Dropping](./arc-mutex/arc-drop.md)
63+
* [Final Code](./arc-mutex/arc-final.md)
6464
* [FFI](ffi.md)
6565
* [Beneath `std`](beneath-std.md)
6666
* [#[panic_handler]](panic-handler.md)

src/arc-and-mutex.md src/arc-mutex/arc-and-mutex.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
Knowing the theory is all fine and good, but the *best* way to understand
44
something is to use it. To better understand atomics and interior mutability,
5-
we'll be implementing versions of the standard library's Arc and Mutex types.
5+
we'll be implementing versions of the standard library's `Arc` and `Mutex` types.
66

7-
TODO: Mutex
7+
TODO: Write `Mutex` chapters.

src/arc-base.md src/arc-mutex/arc-base.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<T> Arc<T> {
3434
Since we're building a concurrency primitive, we'll need to be able to send it
3535
across threads. Thus, we can implement the `Send` and `Sync` marker traits. For
3636
more information on these, see [the section on `Send` and
37-
`Sync`](send-and-sync.md).
37+
`Sync`](../send-and-sync.md).
3838

3939
This is okay because:
4040
* You can only get a mutable reference to the value inside an `Arc` if and only

src/arc-clone.md src/arc-mutex/arc-clone.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ happens-before relationship but is atomic. When `Drop`ping the Arc, however,
2626
we'll need to atomically synchronize when decrementing the reference count. This
2727
is described more in [the section on the `Drop` implementation for
2828
`Arc`](arc-drop.md). For more information on atomic relationships and Relaxed
29-
ordering, see [the section on atomics](atomics.md).
29+
ordering, see [the section on atomics](../atomics.md).
3030

3131
Thus, the code becomes this:
3232

File renamed without changes.
File renamed without changes.

src/arc-layout.md src/arc-mutex/arc-layout.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ be used where an `Arc<&'a str>` was expected. More importantly, it will give
4141
incorrect ownership information to the drop checker, as it will assume we don't
4242
own any values of type `T`. As this is a structure providing shared ownership of
4343
a value, at some point there will be an instance of this structure that entirely
44-
owns its data. See [the chapter on ownership and lifetimes](ownership.md) for
44+
owns its data. See [the chapter on ownership and lifetimes](../ownership.md) for
4545
all the details on variance and drop check.
4646

4747
To fix the first problem, we can use `NonNull<T>`. Note that `NonNull<T>` is a

src/arc.md src/arc-mutex/arc.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Implementing Arc
22

33
In this section, we'll be implementing a simpler version of `std::sync::Arc`.
4-
Similarly to [the implementation of `Vec` we made earlier](vec.md), we won't be
4+
Similarly to [the implementation of `Vec` we made earlier](../vec/vec.md), we won't be
55
taking advantage of as many optimizations, intrinsics, or unstable code as the
66
standard library may.
77

src/intro.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# The Rustonomicon
2+
3+
## The Dark Arts of Unsafe Rust
4+
5+
> THE KNOWLEDGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF UNLEASHING INDESCRIBABLE HORRORS THAT SHATTER YOUR PSYCHE AND SET YOUR MIND ADRIFT IN THE UNKNOWABLY INFINITE COSMOS.
6+
7+
The Rustonomicon digs into all the awful details that you need to understand when writing Unsafe Rust programs.
8+
9+
Should you wish a long and happy career of writing Rust programs, you should turn back now and forget you ever saw this book.
10+
It is not necessary.
11+
However if you intend to write unsafe code — or just want to dig into the guts of the language — this book contains lots of useful information.
12+
13+
Unlike *[The Rust Programming Language][trpl]*, we will be assuming considerable prior knowledge.
14+
In particular, you should be comfortable with basic systems programming and Rust.
15+
If you don't feel comfortable with these topics, you should consider reading [The Book][trpl] first.
16+
That said, we won't assume you have read it, and we will take care to occasionally give a refresher on the basics where appropriate.
17+
You can skip straight to this book if you want; just know that we won't be explaining everything from the ground up.
18+
19+
This book exists primarily as a high-level companion to [The Reference][ref].
20+
Where The Reference exists to detail the syntax and semantics of every part of the language, The Rustonomicon exists to describe how to use those pieces together, and the issues that you will have in doing so.
21+
22+
The Reference will tell you the syntax and semantics of references, destructors, and unwinding, but it won't tell you how combining them can lead to exception-safety issues, or how to deal with those issues.
23+
24+
It should be noted that we haven't synced The Rustnomicon and The Reference well, so they may have a duplicate content.
25+
In general, if the two documents disagree, The Reference should be assumed to be correct (it isn't yet considered normative, it's just better maintained).
26+
27+
Topics that are within the scope of this book include: the meaning of (un)safety, unsafe primitives provided by the language and standard library, techniques for creating safe abstractions with those unsafe primitives, subtyping and variance, exception-safety (panic/unwind-safety), working with uninitialized memory, type punning, concurrency, interoperating with other languages (FFI), optimization tricks, how constructs lower to compiler/OS/hardware primitives, how to **not** make the memory model people angry, how you're **going** to make the memory model people angry, and more.
28+
29+
The Rustonomicon is not a place to exhaustively describe the semantics and guarantees of every single API in the standard library, nor is it a place to exhaustively describe every feature of Rust.
30+
31+
[trpl]: ../book/index.html
32+
[ref]: ../reference/index.html

src/vec-alloc.md src/vec/vec-alloc.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ impl<T> Vec<T> {
202202
# fn main() {}
203203
```
204204

205-
[Global]: ../std/alloc/struct.Global.html
206-
[handle_alloc_error]: ../alloc/alloc/fn.handle_alloc_error.html
207-
[alloc]: ../alloc/alloc/fn.alloc.html
208-
[realloc]: ../alloc/alloc/fn.realloc.html
209-
[dealloc]: ../alloc/alloc/fn.dealloc.html
210-
[std_alloc]: ../alloc/alloc/index.html
205+
[Global]: ../../std/alloc/struct.Global.html
206+
[handle_alloc_error]: ../../alloc/alloc/fn.handle_alloc_error.html
207+
[alloc]: ../../alloc/alloc/fn.alloc.html
208+
[realloc]: ../../alloc/alloc/fn.realloc.html
209+
[dealloc]: ../../alloc/alloc/fn.dealloc.html
210+
[std_alloc]: ../../alloc/alloc/index.html
File renamed without changes.
File renamed without changes.

src/vec-drain.md src/vec/vec-drain.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ impl<T> Vec<T> {
149149
For more details on the `mem::forget` problem, see the
150150
[section on leaks][leaks].
151151

152-
[leaks]: leaking.html
152+
[leaks]: ../leaking.html
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/vec-layout.md src/vec/vec-layout.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ unsafe impl<T: Sync> Sync for Vec<T> {}
5656
# fn main() {}
5757
```
5858

59-
[ownership]: ownership.html
60-
[NonNull]: ../std/ptr/struct.NonNull.html
59+
[ownership]: ../ownership.html
60+
[NonNull]: ../../std/ptr/struct.NonNull.html
File renamed without changes.

src/vec-raw.md src/vec/vec-raw.md

File renamed without changes.
File renamed without changes.

src/vec.md src/vec/vec.md

File renamed without changes.

0 commit comments

Comments
 (0)