File tree 8 files changed +47
-21
lines changed
8 files changed +47
-21
lines changed Original file line number Diff line number Diff line change @@ -514,7 +514,7 @@ field_expr : expr '.' ident ;
514
514
### Array expressions
515
515
516
516
``` antlr
517
- array_expr : '[' "mut" ? vec_elems ? ']' ;
517
+ array_expr : '[' "mut" ? array_elems ? ']' ;
518
518
519
519
array_elems : [expr [',' expr]*] | [expr ',' ".." expr] ;
520
520
```
Original file line number Diff line number Diff line change @@ -2847,7 +2847,7 @@ automatically dereferenced to make the field access possible.
2847
2847
### Array expressions
2848
2848
2849
2849
``` {.ebnf .gram}
2850
- array_expr : '[' "mut" ? vec_elems ? ']' ;
2850
+ array_expr : '[' "mut" ? array_elems ? ']' ;
2851
2851
2852
2852
array_elems : [expr [',' expr]*] | [expr ';' expr] ;
2853
2853
```
Original file line number Diff line number Diff line change 16
16
* [ Standard Input] ( standard-input.md )
17
17
* [ Guessing Game] ( guessing-game.md )
18
18
* [ II: Intermediate Rust] ( intermediate.md )
19
- * [ More Strings] ( more-strings.md )
20
19
* [ Crates and Modules] ( crates-and-modules.md )
21
20
* [ Testing] ( testing.md )
22
21
* [ Pointers] ( pointers.md )
23
22
* [ Ownership] ( ownership.md )
23
+ * [ More Strings] ( more-strings.md )
24
24
* [ Patterns] ( patterns.md )
25
25
* [ Method Syntax] ( method-syntax.md )
26
26
* [ Closures] ( closures.md )
Original file line number Diff line number Diff line change @@ -223,15 +223,8 @@ method which has this signature:
223
223
fn lock(&self) -> LockResult<MutexGuard<T>>
224
224
```
225
225
226
- If we [ look at the code for MutexGuard] ( https://github.com/rust-lang/rust/blob/ca4b9674c26c1de07a2042cb68e6a062d7184cef/src/libstd/sync/mutex.rs#L172 ) , we'll see
227
- this:
228
-
229
- ``` ignore
230
- __marker: marker::NoSend,
231
- ```
232
-
233
- Because our guard is ` NoSend ` , it's not ` Send ` . Which means we can't actually
234
- transfer the guard across thread boundaries, which gives us our error.
226
+ Because ` Send ` is not implemented for ` MutexGuard<T> ` , we can't transfer the
227
+ guard across thread boundaries, which gives us our error.
235
228
236
229
We can use ` Arc<T> ` to fix this. Here's the working version:
237
230
Original file line number Diff line number Diff line change @@ -50,7 +50,29 @@ You can think of this first parameter as being the `x` in `x.foo()`. The three
50
50
variants correspond to the three kinds of thing ` x ` could be: ` self ` if it's
51
51
just a value on the stack, ` &self ` if it's a reference, and ` &mut self ` if it's
52
52
a mutable reference. We should default to using ` &self ` , as it's the most
53
- common.
53
+ common. Here's an example of all three variants:
54
+
55
+ ``` rust
56
+ struct Circle {
57
+ x : f64 ,
58
+ y : f64 ,
59
+ radius : f64 ,
60
+ }
61
+
62
+ impl Circle {
63
+ fn reference (& self ) {
64
+ println! (" taking self by reference!" );
65
+ }
66
+
67
+ fn mutable_reference (& mut self ) {
68
+ println! (" taking self by mutable reference!" );
69
+ }
70
+
71
+ fn takes_ownership (self ) {
72
+ println! (" taking ownership of self!" );
73
+ }
74
+ }
75
+ ```
54
76
55
77
Finally, as you may remember, the value of the area of a circle is ` π*r² ` .
56
78
Because we took the ` &self ` parameter to ` area ` , we can use it just like any
Original file line number Diff line number Diff line change @@ -278,7 +278,18 @@ This will print:
278
278
279
279
Many more bytes than graphemes!
280
280
281
- # Other Documentation
281
+ # ` Deref ` coercions
282
282
283
- * [ the ` &str ` API documentation] ( ../std/str/index.html )
284
- * [ the ` String ` API documentation] ( ../std/string/index.html )
283
+ References to ` String ` s will automatically coerce into ` &str ` s. Like this:
284
+
285
+ ```
286
+ fn hello(s: &str) {
287
+ println!("Hello, {}!", s);
288
+ }
289
+
290
+ let slice = "Steve";
291
+ let string = "Steve".to_string();
292
+
293
+ hello(slice);
294
+ hello(&string);
295
+ ```
Original file line number Diff line number Diff line change @@ -634,8 +634,8 @@ use-case for boxes.
634
634
### Returning data
635
635
636
636
This is important enough to have its own section entirely. The TL;DR is this:
637
- you don't generally want to return pointers, even when you might in a language
638
- like C or C++.
637
+ you don't want to return pointers, even when you might in a language like C or
638
+ C++.
639
639
640
640
See [ Returning Pointers] ( #returning-pointers ) below for more.
641
641
Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ impl Command {
264
264
/// By default, stdin, stdout and stderr are captured (and used to
265
265
/// provide the resulting output).
266
266
///
267
- /// # Example
267
+ /// # Examples
268
268
///
269
269
/// ```
270
270
/// # #![feature(process)]
@@ -275,8 +275,8 @@ impl Command {
275
275
/// });
276
276
///
277
277
/// println!("status: {}", output.status);
278
- /// println!("stdout: {}", String::from_utf8_lossy(output.stdout.as_slice() ));
279
- /// println!("stderr: {}", String::from_utf8_lossy(output.stderr.as_slice() ));
278
+ /// println!("stdout: {}", String::from_utf8_lossy(& output.stdout));
279
+ /// println!("stderr: {}", String::from_utf8_lossy(& output.stderr));
280
280
/// ```
281
281
#[ stable( feature = "process" , since = "1.0.0" ) ]
282
282
pub fn output ( & mut self ) -> io:: Result < Output > {
You can’t perform that action at this time.
0 commit comments