Skip to content

Commit 130c8ae

Browse files
committed
Merge pull request #21075 from iKevinY/intro-changes
Various changes to Rust Introduction Reviewed-by: steveklabnik
2 parents 6631b85 + 31ac1fb commit 130c8ae

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/doc/intro.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ accomplishes these goals by being memory safe without using garbage collection.
55

66
This introduction will give you a rough idea of what Rust is like, eliding many
77
details. It does not require prior experience with systems programming, but you
8-
may find the syntax easier if you've used a 'curly brace' programming language
8+
may find the syntax easier if you've used a "curly brace" programming language
99
before, like C or JavaScript. The concepts are more important than the syntax,
1010
so don't worry if you don't get every last detail: you can read [The
1111
Rust Programming Language](book/index.html) to get a more complete explanation.
@@ -15,7 +15,7 @@ Rust to follow along. If you'd like to anyway, check out [the
1515
homepage](http://rust-lang.org) for explanation.
1616

1717
To show off Rust, let's talk about how easy it is to get started with Rust.
18-
Then, we'll talk about Rust's most interesting feature, **ownership**, and
18+
Then, we'll talk about Rust's most interesting feature, *ownership*, and
1919
then discuss how it makes concurrency easier to reason about. Finally,
2020
we'll talk about how Rust breaks down the perceived dichotomy between speed
2121
and safety.
@@ -57,7 +57,7 @@ version = "0.0.1"
5757
authors = ["Your Name <[email protected]>"]
5858
```
5959

60-
This is called a **manifest**, and it contains all of the metadata that Cargo
60+
This is called a *manifest*, and it contains all of the metadata that Cargo
6161
needs to compile your project.
6262

6363
Here's what's in `src/main.rs`:
@@ -68,7 +68,7 @@ fn main() {
6868
}
6969
```
7070

71-
Cargo generated a 'hello world' for us. We'll talk more about the syntax here
71+
Cargo generated a "Hello World" for us. We'll talk more about the syntax here
7272
later, but that's what Rust code looks like! Let's compile and run it:
7373

7474
```{bash}
@@ -146,8 +146,8 @@ Enough about tools, let's talk code!
146146

147147
# Ownership
148148

149-
Rust's defining feature is 'memory safety without garbage collection.' Let's
150-
take a moment to talk about what that means. **Memory safety** means that the
149+
Rust's defining feature is "memory safety without garbage collection". Let's
150+
take a moment to talk about what that means. *Memory safety* means that the
151151
programming language eliminates certain kinds of bugs, such as [buffer
152152
overflows](http://en.wikipedia.org/wiki/Buffer_overflow) and [dangling
153153
pointers](http://en.wikipedia.org/wiki/Dangling_pointer). These problems occur
@@ -170,7 +170,7 @@ We make an array, `v`, and then call `push` on it. `push` is a method which
170170
adds an element to the end of an array.
171171

172172
Next, we make a new variable, `x`, that's equal to the first element of
173-
the array. Simple, but this is where the 'bug' will appear.
173+
the array. Simple, but this is where the "bug" will appear.
174174

175175
Let's keep going. We then call `push` again, pushing "world" onto the
176176
end of the array. `v` now is `["Hello", "world"]`.
@@ -222,7 +222,7 @@ its length changes, we may need to allocate more memory. In Ruby, this happens
222222
as well, we just don't think about it very often. So why does the C++ version
223223
segfault when we allocate more memory?
224224

225-
The answer is that in the C++ version, `x` is a **reference** to the memory
225+
The answer is that in the C++ version, `x` is a *reference* to the memory
226226
location where the first element of the array is stored. But in Ruby, `x` is a
227227
standalone value, not connected to the underyling array at all. Let's dig into
228228
the details for a moment. Your program has access to memory, provided to it by
@@ -332,11 +332,11 @@ error: aborting due to previous error
332332
333333
When we try to mutate the array by `push`ing it the second time, Rust throws
334334
an error. It says that we "cannot borrow v as mutable because it is also
335-
borrowed as immutable." What's up with "borrowed"?
335+
borrowed as immutable." What does it mean by "borrowed"?
336336
337-
In Rust, the type system encodes the notion of **ownership**. The variable `v`
338-
is an "owner" of the vector. When we make a reference to `v`, we let that
339-
variable (in this case, `x`) 'borrow' it for a while. Just like if you own a
337+
In Rust, the type system encodes the notion of *ownership*. The variable `v`
338+
is an *owner* of the vector. When we make a reference to `v`, we let that
339+
variable (in this case, `x`) *borrow* it for a while. Just like if you own a
340340
book, and you lend it to me, I'm borrowing the book.
341341
342342
So, when I try to modify the vector with the second call to `push`, I need
@@ -408,7 +408,7 @@ child thread when it goes out of scope. Because we `collect` these guards into
408408
a `Vec<T>`, and that vector goes out of scope at the end of our program, our
409409
program will wait for every thread to finish before finishing.
410410
411-
One common form of problem in concurrent programs is a 'data race.'
411+
One common form of problem in concurrent programs is a *data race*.
412412
This occurs when two different threads attempt to access the same
413413
location in memory in a non-synchronized way, where at least one of
414414
them is a write. If one thread is attempting to read, and one thread
@@ -461,9 +461,9 @@ code tries to make three owners. This may cause a safety problem, so
461461
Rust disallows it.
462462
463463
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
464-
"Arc" stands for "atomically reference counted." In other words, an Arc will
464+
*Arc* stands for "atomically reference counted". In other words, an Arc will
465465
keep track of the number of references to something, and not free the
466-
associated resource until the count is zero. The 'atomic' portion refers to an
466+
associated resource until the count is zero. The *atomic* portion refers to an
467467
Arc's usage of concurrency primitives to atomically update the count, making it
468468
safe across threads. If we use an Arc, we can have our three references. But,
469469
an Arc does not allow mutable borrows of the data it holds, and we want to
@@ -526,13 +526,13 @@ give us assurance _at compile time_ that we weren't doing something incorrect
526526
with regards to concurrency. In order to share ownership, we were forced to be
527527
explicit and use a mechanism to ensure that it would be properly handled.
528528
529-
# Safety _and_ speed
529+
# Safety _and_ Speed
530530
531-
Safety and speed are always presented as a continuum. On one hand, you have
532-
maximum speed, but no safety. On the other, you have absolute safety, with no
533-
speed. Rust seeks to break out of this mode by introducing safety at compile
534-
time, ensuring that you haven't done anything wrong, while compiling to the
535-
same low-level code you'd expect without the safety.
531+
Safety and speed are always presented as a continuum. At one end of the spectrum,
532+
you have maximum speed, but no safety. On the other end, you have absolute safety
533+
with no speed. Rust seeks to break out of this paradigm by introducing safety at
534+
compile time, ensuring that you haven't done anything wrong, while compiling to
535+
the same low-level code you'd expect without the safety.
536536
537537
As an example, Rust's ownership system is _entirely_ at compile time. The
538538
safety check that makes this an error about moved values:

0 commit comments

Comments
 (0)