Skip to content

Commit 57f7d23

Browse files
committed
---
yaml --- r: 211679 b: refs/heads/auto c: f56782a h: refs/heads/master i: 211677: be5f17a 211675: ea769ad 211671: 1dcb522 211663: 5fc37fb 211647: 9f887d0 v: v3
1 parent d89df1a commit 57f7d23

File tree

168 files changed

+1554
-2831
lines changed

Some content is hidden

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

168 files changed

+1554
-2831
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 677367599e8383c355b8e8261cafe3ce44c9c6de
13+
refs/heads/auto: f56782ab9c8d0f64b9a714cc24d925a81ac3211b
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/trpl/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* [Learn Rust](learn-rust.md)
88
* [Guessing Game](guessing-game.md)
99
* [Dining Philosophers](dining-philosophers.md)
10-
* [Rust inside other languages](rust-inside-other-languages.md)
10+
* [Rust Inside Other Languages](rust-inside-other-languages.md)
1111
* [Effective Rust](effective-rust.md)
1212
* [The Stack and the Heap](the-stack-and-the-heap.md)
1313
* [Testing](testing.md)

branches/auto/src/doc/trpl/installing-rust.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ Some people, and somewhat rightfully so, get very upset when we tell you to
4343
`curl | sh`. Basically, when you do this, you are trusting that the good
4444
people who maintain Rust aren't going to hack your computer and do bad things.
4545
That's a good instinct! If you're one of those people, please check out the
46-
documentation on [building Rust from Source][from source], or [the official
47-
binary downloads][install page].
46+
documentation on [building Rust from Source][from-source], or [the official
47+
binary downloads][install-page].
4848

49-
[from source]: https://github.com/rust-lang/rust#building-from-source
50-
[install page]: http://www.rust-lang.org/install.html
49+
[from-source]: https://github.com/rust-lang/rust#building-from-source
50+
[install-page]: http://www.rust-lang.org/install.html
5151

5252
Oh, we should also mention the officially supported platforms:
5353

branches/auto/src/doc/trpl/macros.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ mind.
3030

3131
# Defining a macro
3232

33-
You may have seen the `vec!` macro, used to initialize a [vector][] with any
34-
number of elements.
33+
You may have seen the `vec!` macro, used to initialize a [vector][vector] with
34+
any number of elements.
3535

3636
[vector]: vectors.html
3737

@@ -349,7 +349,7 @@ fn main() {
349349
}
350350
```
351351

352-
This holds for `let` bindings and loop labels, but not for [items][].
352+
This holds for `let` bindings and loop labels, but not for [items][items].
353353
So the following code does compile:
354354

355355
```rust
@@ -470,15 +470,15 @@ which syntactic form it matches.
470470
* `stmt`: a single statement. Example: `let x = 3`.
471471
* `block`: a brace-delimited sequence of statements. Example:
472472
`{ log(error, "hi"); return 12; }`.
473-
* `item`: an [item][]. Examples: `fn foo() { }`; `struct Bar;`.
473+
* `item`: an [item][item]. Examples: `fn foo() { }`; `struct Bar;`.
474474
* `meta`: a "meta item", as found in attributes. Example: `cfg(target_os = "windows")`.
475475
* `tt`: a single token tree.
476476

477477
There are additional rules regarding the next token after a metavariable:
478478

479479
* `expr` variables may only be followed by one of: `=> , ;`
480480
* `ty` and `path` variables may only be followed by one of: `=> , : = > as`
481-
* `pat` variables may only be followed by one of: `=> , =`
481+
* `pat` variables may only be followed by one of: `=> , = if in`
482482
* Other variables may be followed by any token.
483483

484484
These rules provide some flexibility for Rust’s syntax to evolve without

branches/auto/src/doc/trpl/nightly-rust.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ Some people, and somewhat rightfully so, get very upset when we tell you to
4646
`curl | sh`. Basically, when you do this, you are trusting that the good
4747
people who maintain Rust aren't going to hack your computer and do bad things.
4848
That's a good instinct! If you're one of those people, please check out the
49-
documentation on [building Rust from Source][from source], or [the official
50-
binary downloads][install page].
49+
documentation on [building Rust from Source][from-source], or [the official
50+
binary downloads][install-page].
5151

52-
[from source]: https://github.com/rust-lang/rust#building-from-source
53-
[install page]: http://www.rust-lang.org/install.html
52+
[from-source]: https://github.com/rust-lang/rust#building-from-source
53+
[install-page]: http://www.rust-lang.org/install.html
5454

5555
Oh, we should also mention the officially supported platforms:
5656

@@ -91,9 +91,9 @@ If not, there are a number of places where you can get help. The easiest is
9191
[the #rust IRC channel on irc.mozilla.org][irc], which you can access through
9292
[Mibbit][mibbit]. Click that link, and you'll be chatting with other Rustaceans
9393
(a silly nickname we call ourselves), and we can help you out. Other great
94-
resources include [the user’s forum][users], and [Stack Overflow][stack overflow].
94+
resources include [the user’s forum][users], and [Stack Overflow][stackoverflow].
9595

9696
[irc]: irc://irc.mozilla.org/#rust
9797
[mibbit]: http://chat.mibbit.com/?server=irc.mozilla.org&channel=%23rust
9898
[users]: http://users.rust-lang.org/
99-
[stack overflow]: http://stackoverflow.com/questions/tagged/rust
99+
[stackoverflow]: http://stackoverflow.com/questions/tagged/rust

branches/auto/src/doc/trpl/rust-inside-other-languages.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@ Rust’s greatest strengths: a lack of a substantial runtime.
66
As organizations grow, they increasingly rely on a multitude of programming
77
languages. Different programming languages have different strengths and
88
weaknesses, and a polyglot stack lets you use a particular language where
9-
its strengths make sense, and use a different language where it’s weak.
9+
its strengths make sense and a different one where it’s weak.
1010

1111
A very common area where many programming languages are weak is in runtime
1212
performance of programs. Often, using a language that is slower, but offers
13-
greater programmer productivity is a worthwhile trade-off. To help mitigate
14-
this, they provide a way to write some of your system in C, and then call
15-
the C code as though it were written in the higher-level language. This is
13+
greater programmer productivity, is a worthwhile trade-off. To help mitigate
14+
this, they provide a way to write some of your system in C and then call
15+
that C code as though it were written in the higher-level language. This is
1616
called a ‘foreign function interface’, often shortened to ‘FFI’.
1717

1818
Rust has support for FFI in both directions: it can call into C code easily,
1919
but crucially, it can also be called _into_ as easily as C. Combined with
2020
Rust’s lack of a garbage collector and low runtime requirements, this makes
2121
Rust a great candidate to embed inside of other languages when you need
22-
some extra oomph.
22+
that extra oomph.
2323

2424
There is a whole [chapter devoted to FFI][ffi] and its specifics elsewhere in
2525
the book, but in this chapter, we’ll examine this particular use-case of FFI,
26-
with three examples, in Ruby, Python, and JavaScript.
26+
with examples in Ruby, Python, and JavaScript.
2727

2828
[ffi]: ffi.html
2929

@@ -40,18 +40,18 @@ optimizations can stack allocate particular numbers, but rather than relying
4040
on an optimizer to do its job, we may want to ensure that we’re always using
4141
primitive number types rather than some sort of object type.
4242

43-
Second, many languages have a ‘global interpreter lock’, which limits
43+
Second, many languages have a ‘global interpreter lock’ (GIL), which limits
4444
concurrency in many situations. This is done in the name of safety, which is
4545
a positive effect, but it limits the amount of work that can be done at the
4646
same time, which is a big negative.
4747

4848
To emphasize these two aspects, we’re going to create a little project that
49-
uses these two aspects heavily. Since the focus of the example is the embedding
50-
of Rust into the languages, rather than the problem itself, we’ll just use a
49+
uses these two aspects heavily. Since the focus of the example is to embed
50+
Rust into other languages, rather than the problem itself, we’ll just use a
5151
toy example:
5252

5353
> Start ten threads. Inside each thread, count from one to five million. After
54-
> All ten threads are finished, print out ‘done!’.
54+
> all ten threads are finished, print out ‘done!’.
5555
5656
I chose five million based on my particular computer. Here’s an example of this
5757
code in Ruby:
@@ -69,7 +69,7 @@ threads = []
6969
end
7070
end
7171

72-
threads.each {|t| t.join }
72+
threads.each { |t| t.join }
7373
puts "done!"
7474
```
7575

@@ -82,12 +82,12 @@ sort of process monitoring tool, like `top`, I can see that it only uses one
8282
core on my machine. That’s the GIL kicking in.
8383

8484
While it’s true that this is a synthetic program, one can imagine many problems
85-
that are similar to this in the real world. For our purposes, spinning up some
85+
that are similar to this in the real world. For our purposes, spinning up a few
8686
busy threads represents some sort of parallel, expensive computation.
8787

8888
# A Rust library
8989

90-
Let’s re-write this problem in Rust. First, let’s make a new project with
90+
Let’s rewrite this problem in Rust. First, let’s make a new project with
9191
Cargo:
9292

9393
```bash
@@ -129,7 +129,7 @@ src/lib.rs:3 fn process() {
129129
src/lib.rs:4 let handles: Vec<_> = (0..10).map(|_| {
130130
src/lib.rs:5 thread::spawn(|| {
131131
src/lib.rs:6 let mut x = 0;
132-
src/lib.rs:7 for _ in (0..5_000_001) {
132+
src/lib.rs:7 for _ in (0..5_000_000) {
133133
src/lib.rs:8 x += 1
134134
...
135135
src/lib.rs:6:17: 6:22 warning: variable `x` is assigned to, but never used, #[warn(unused_variables)] on by default
@@ -151,7 +151,7 @@ Finally, we join on each thread.
151151
Right now, however, this is a Rust library, and it doesn’t expose anything
152152
that’s callable from C. If we tried to hook this up to another language right
153153
now, it wouldn’t work. We only need to make two small changes to fix this,
154-
though. The first is modify the beginning of our code:
154+
though. The first is to modify the beginning of our code:
155155
156156
```rust,ignore
157157
#[no_mangle]
@@ -161,7 +161,7 @@ pub extern fn process() {
161161
We have to add a new attribute, `no_mangle`. When you create a Rust library, it
162162
changes the name of the function in the compiled output. The reasons for this
163163
are outside the scope of this tutorial, but in order for other languages to
164-
know how to call the function, we need to not do that. This attribute turns
164+
know how to call the function, we can’t do that. This attribute turns
165165
that behavior off.
166166
167167
The other change is the `pub extern`. The `pub` means that this function should
@@ -178,7 +178,7 @@ crate-type = ["dylib"]
178178
```
179179
180180
This tells Rust that we want to compile our library into a standard dynamic
181-
library. By default, Rust compiles into an ‘rlib’, a Rust-specific format.
181+
library. By default, Rust compiles an ‘rlib’, a Rust-specific format.
182182
183183
Let’s build the project now:
184184
@@ -204,7 +204,7 @@ Now that we’ve got our Rust library built, let’s use it from our Ruby.
204204
205205
# Ruby
206206
207-
Open up a `embed.rb` file inside of our project, and do this:
207+
Open up an `embed.rb` file inside of our project, and do this:
208208
209209
```ruby
210210
require 'ffi'
@@ -217,7 +217,7 @@ end
217217

218218
Hello.process
219219

220-
puts "done!"
220+
puts 'done!'
221221
```
222222
223223
Before we can run this, we need to install the `ffi` gem:
@@ -241,7 +241,7 @@ done!
241241
$
242242
```
243243
244-
Whoah, that was fast! On my system, this took `0.086` seconds, rather than
244+
Whoa, that was fast! On my system, this took `0.086` seconds, rather than
245245
the two seconds the pure Ruby version took. Let’s break down this Ruby
246246
code:
247247
@@ -258,11 +258,11 @@ module Hello
258258
ffi_lib 'target/release/libembed.so'
259259
```
260260
261-
The `ffi` gem’s authors recommend using a module to scope the functions
262-
we’ll import from the shared library. Inside, we `extend` the necessary
263-
`FFI::Library` module, and then call `ffi_lib` to load up our shared
264-
object library. We just pass it the path that our library is stored,
265-
which as we saw before, is `target/release/libembed.so`.
261+
The `Hello` module is used to attach the native functions from the shared
262+
library. Inside, we `extend` the necessary `FFI::Library` module and then call
263+
`ffi_lib` to load up our shared object library. We just pass it the path that
264+
our library is stored, which, as we saw before, is
265+
`target/release/libembed.so`.
266266
267267
```ruby
268268
attach_function :process, [], :void
@@ -280,10 +280,10 @@ Hello.process
280280
281281
This is the actual call into Rust. The combination of our `module`
282282
and the call to `attach_function` sets this all up. It looks like
283-
a Ruby function, but is actually Rust!
283+
a Ruby function but is actually Rust!
284284
285285
```ruby
286-
puts "done!"
286+
puts 'done!'
287287
```
288288
289289
Finally, as per our project’s requirements, we print out `done!`.
@@ -329,7 +329,7 @@ After that installs, we can use it:
329329
var ffi = require('ffi');
330330

331331
var lib = ffi.Library('target/release/libembed', {
332-
'process': [ 'void', [] ]
332+
'process': ['void', []]
333333
});
334334

335335
lib.process();
@@ -340,7 +340,7 @@ console.log("done!");
340340
It looks more like the Ruby example than the Python example. We use
341341
the `ffi` module to get access to `ffi.Library()`, which loads up
342342
our shared object. We need to annotate the return type and argument
343-
types of the function, which are 'void' for return, and an empty
343+
types of the function, which are `void` for return and an empty
344344
array to signify no arguments. From there, we just call it and
345345
print the result.
346346

branches/auto/src/doc/trpl/strings.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ fn main() {
4949
}
5050
```
5151

52+
This coercion does not happen for functions that accept one of `&str`’s traits
53+
instead of `&str`. For example, [`TcpStream::connect`][connect] has a parameter
54+
of type `ToSocketAddrs`. A `&str` is okay but a `String` must be explicitly
55+
converted using `&*`.
56+
57+
```rust,no_run
58+
use std::net::TcpStream;
59+
60+
TcpStream::connect("192.168.0.1:3000"); // &str parameter
61+
62+
let addr_string = "192.168.0.1:3000".to_string();
63+
TcpStream::connect(&*addr_string); // convert addr_string to &str
64+
```
65+
5266
Viewing a `String` as a `&str` is cheap, but converting the `&str` to a
5367
`String` involves allocating memory. No reason to do that unless you have to!
5468

@@ -127,3 +141,4 @@ This is because `&String` can automatically coerce to a `&str`. This is a
127141
feature called ‘[`Deref` coercions][dc]’.
128142

129143
[dc]: deref-coercions.html
144+
[connect]: ../std/net/struct.TcpStream.html#method.connect

branches/auto/src/doc/trpl/the-stack-and-the-heap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ At the end of `bar()`, it calls `baz()`:
454454
| (2<sup>30</sup>) - 1 | | 5 |
455455
| ... | ... | ... |
456456
| 12 | g | 100 |
457-
| 11 | f | 4 |
457+
| 11 | f | 9 |
458458
| 10 | e | 9 |
459459
| 9 | d | (2<sup>30</sup>) - 1 |
460460
| 8 | c | 5 |

0 commit comments

Comments
 (0)