@@ -21,7 +21,7 @@ fn succ(x: &int) -> int { *x + 1 }
2121
2222So I wrote this code to try it out:
2323
24- ~~~ rust {.xfail-test}
24+ ~~~ rust{.xfail-test}
2525fn main() {
2626 let number = 5;
2727 let succ_number = succ(number);
@@ -73,7 +73,7 @@ However.
7373Here are the use-cases for pointers. I've prefixed them with the name of the
7474pointer that satisfies that use-case:
7575
76- 1 . Owned: ~ Trait must be a pointer, becuase you don't know the size of the
76+ 1 . Owned: ~ Trait must be a pointer, because you don't know the size of the
7777object, so indirection is mandatory.
78782 . Owned: You need a recursive data structure. These can be infinite sized, so
7979indirection is mandatory.
@@ -85,18 +85,18 @@ common, such as C++, please read "A note..." below.
8585or impossible. This is only often useful when a program is very large or very
8686complicated. Using a managed pointer will activate Rust's garbage collection
8787mechanism.
88- 5: Reference: You're writing a function, and you need a pointer, but you don't
88+ 5 . Reference: You're writing a function, and you need a pointer, but you don't
8989care about its ownership. If you make the argument a reference, callers
9090can send in whatever kind they want.
9191
92- Five exceptions. That's it. Otherwise, you shouldn't need them. Be skeptical
92+ Five exceptions. That's it. Otherwise, you shouldn't need them. Be sceptical
9393of pointers in Rust: use them for a deliberate purpose, not just to make the
9494compiler happy.
9595
9696## A note for those proficient in pointers
9797
9898If you're coming to Rust from a language like C or C++, you may be used to
99- passing things by reference, or passing things by pointer. In some langauges ,
99+ passing things by reference, or passing things by pointer. In some languages ,
100100like Java, you can't even have objects without a pointer to them. Therefore, if
101101you were writing this Rust code:
102102
@@ -150,7 +150,7 @@ fn main() {
150150}
151151~~~
152152
153- But won't this be inefficent ? Well, that's a complicated question, but it's
153+ But won't this be inefficient ? Well, that's a complicated question, but it's
154154important to know that Rust, like C and C++, store aggregate data types
155155'unboxed,' whereas languages like Java and Ruby store these types as 'boxed.'
156156For smaller structs, this way will be more efficient. For larger ones, it may
@@ -173,7 +173,7 @@ These two properties make for three use cases.
173173
174174## References to Traits
175175
176- Traits must be referenced through a pointer, becuase the struct that implements
176+ Traits must be referenced through a pointer, because the struct that implements
177177the trait may be a different size than a different struct that implements the
178178trait. Therefore, unboxed traits don't make any sense, and aren't allowed.
179179
@@ -199,7 +199,7 @@ This prints:
199199Cons(1, ~Cons(2, ~Cons(3, ~Nil)))
200200~~~
201201
202- The inner lists _ must_ be an owned pointer, becuase we can't know how many
202+ The inner lists _ must_ be an owned pointer, because we can't know how many
203203elements are in the list. Without knowing the length, we don't know the size,
204204and therefore require the indirection that pointers offer.
205205
@@ -261,7 +261,7 @@ program is very large and complicated.
261261
262262For example, let's say you're using an owned pointer, and you want to do this:
263263
264- ~~~ rust {.xfail-test}
264+ ~~~ rust{.xfail-test}
265265struct Point {
266266 x: int,
267267 y: int,
@@ -315,7 +315,7 @@ managed pointers:
3153151 . They activate Rust's garbage collector. Other pointer types don't share this
316316drawback.
3173172 . You cannot pass this data to another task. Shared ownership across
318- concurrency boundaries is the source of endless pain in other langauges , so
318+ concurrency boundaries is the source of endless pain in other languages , so
319319Rust does not let you do this.
320320
321321# References
@@ -355,7 +355,7 @@ takes in two references, but we give it a managed and unique pointer. Of
355355course, if this were a real program, we wouldn't have any of these pointers,
356356they're just there to demonstrate the concepts.
357357
358- So how is this hard? Well, because we're igorning ownership, the compiler needs
358+ So how is this hard? Well, because we're ignoring ownership, the compiler needs
359359to take great care to make sure that everything is safe. Despite their complete
360360safety, a reference's representation at runtime is the same as that of
361361an ordinary pointer in a C program. They introduce zero overhead. The compiler
@@ -365,14 +365,14 @@ This theory is called 'region pointers,' and involve a concept called
365365'lifetimes'. Here's the simple explanation: would you expect this code to
366366compile?
367367
368- ~~~ rust {.xfail-test}
368+ ~~~ rust{.xfail-test}
369369fn main() {
370370 println(x.to_str());
371371 let x = 5;
372372}
373373~~~
374374
375- Probably not. That's becuase you know that the name ` x ` is valid from where
375+ Probably not. That's because you know that the name ` x ` is valid from where
376376it's declared to when it goes out of scope. In this case, that's the end of
377377the ` main ` function. So you know this code will cause an error. We call this
378378duration a 'lifetime'. Let's try a more complex example:
@@ -394,7 +394,7 @@ Here, we're borrowing a pointer to `x` inside of the `if`. The compiler, however
394394is able to determine that that pointer will go out of scope without ` x ` being
395395mutated, and therefore, lets us pass. This wouldn't work:
396396
397- ~~~ rust {.xfail-test}
397+ ~~~ rust{.xfail-test}
398398fn main() {
399399 let mut x = ~5;
400400 if *x < 10 {
@@ -427,7 +427,7 @@ great detail, so if you want the full details, check that out.
427427
428428# Returning Pointers
429429
430- We've talked a lot about funtions that accept various kinds of pointers, but
430+ We've talked a lot about functions that accept various kinds of pointers, but
431431what about returning them? Here's the rule of thumb: only return a unique or
432432managed pointer if you were given one in the first place.
433433
0 commit comments