Skip to content

Commit 1fd4c3b

Browse files
Clinton Ryanbrson
Clinton Ryan
authored andcommitted
Fixed code snippets
1 parent 7cfce50 commit 1fd4c3b

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

doc/guide-pointers.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn succ(x: &int) -> int { *x + 1 }
2121

2222
So I wrote this code to try it out:
2323

24-
~~~rust {.xfail-test}
24+
~~~rust{.xfail-test}
2525
fn main() {
2626
let number = 5;
2727
let succ_number = succ(number);
@@ -73,7 +73,7 @@ However.
7373
Here are the use-cases for pointers. I've prefixed them with the name of the
7474
pointer 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
7777
object, so indirection is mandatory.
7878
2. Owned: You need a recursive data structure. These can be infinite sized, so
7979
indirection is mandatory.
@@ -85,18 +85,18 @@ common, such as C++, please read "A note..." below.
8585
or impossible. This is only often useful when a program is very large or very
8686
complicated. Using a managed pointer will activate Rust's garbage collection
8787
mechanism.
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
8989
care about its ownership. If you make the argument a reference, callers
9090
can 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
9393
of pointers in Rust: use them for a deliberate purpose, not just to make the
9494
compiler happy.
9595

9696
## A note for those proficient in pointers
9797

9898
If 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,
100100
like Java, you can't even have objects without a pointer to them. Therefore, if
101101
you 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
154154
important 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.'
156156
For 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
177177
the trait may be a different size than a different struct that implements the
178178
trait. Therefore, unboxed traits don't make any sense, and aren't allowed.
179179

@@ -199,7 +199,7 @@ This prints:
199199
Cons(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
203203
elements are in the list. Without knowing the length, we don't know the size,
204204
and therefore require the indirection that pointers offer.
205205

@@ -261,7 +261,7 @@ program is very large and complicated.
261261

262262
For 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}
265265
struct Point {
266266
x: int,
267267
y: int,
@@ -315,7 +315,7 @@ managed pointers:
315315
1. They activate Rust's garbage collector. Other pointer types don't share this
316316
drawback.
317317
2. 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
319319
Rust 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
355355
course, if this were a real program, we wouldn't have any of these pointers,
356356
they'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
359359
to take great care to make sure that everything is safe. Despite their complete
360360
safety, a reference's representation at runtime is the same as that of
361361
an 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
366366
compile?
367367

368-
~~~rust {.xfail-test}
368+
~~~rust{.xfail-test}
369369
fn 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
376376
it's declared to when it goes out of scope. In this case, that's the end of
377377
the `main` function. So you know this code will cause an error. We call this
378378
duration 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
394394
is able to determine that that pointer will go out of scope without `x` being
395395
mutated, and therefore, lets us pass. This wouldn't work:
396396

397-
~~~rust {.xfail-test}
397+
~~~rust{.xfail-test}
398398
fn 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
431431
what about returning them? Here's the rule of thumb: only return a unique or
432432
managed pointer if you were given one in the first place.
433433

0 commit comments

Comments
 (0)