|
1.
|
|
|
% The Rust Pointer Guide
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:2
|
|
2.
|
|
|
Rust's pointers are one of its more unique and compelling features. Pointers are also one of the more confusing topics for newcomers to Rust. They can also be confusing for people coming from other languages that support pointers, such as C++. This guide will help you understand this important topic.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:7
|
|
3.
|
|
|
Be sceptical of non-reference pointers in Rust: use them for a deliberate purpose, not just to make the compiler happy. Each pointer type comes with an explanation about when they are appropriate to use. Default to references unless you're in one of those specific situations.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:12
|
|
4.
|
|
|
You may be interested in the [cheat sheet](#cheat-sheet), which gives a quick overview of the types, names, and purpose of the various pointers.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:15
|
|
5.
|
|
|
# An introduction
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:17
|
|
6.
|
|
|
If you aren't familiar with the concept of pointers, here's a short introduction. Pointers are a very fundamental concept in systems programming languages, so it's important to understand them.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:21
|
|
7.
|
|
|
## Pointer Basics
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:23
|
|
8.
|
|
|
When you create a new variable binding, you're giving a name to a value that's stored at a particular location on the stack. (If you're not familiar with the "heap" vs. "stack", please check out [this Stack Overflow question](http://stackoverflow.com/questions/79923/what-and-where-are-the-stack-and-heap), as the rest of this guide assumes you know the difference.) Like this:
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:29
|
|
9.
|
|
|
```{rust}
let x = 5i;
let y = 8i;
```
| location | value |
|----------|-------|
| 0xd3e030 | 5 [tab] |
| 0xd3e028 | 8 |
|
|
|
type: Plain text
|
|
|
[tab] represents a tab character.
Please write it exactly the same way, [tab] , in your
translation.
|
|
|
represents a line break.
Start a new line in the equivalent position in the translation.
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:38
|
|
10.
|
|
|
We're making up memory locations here, they're just sample values. Anyway, the point is that `x`, the name we're using for our variable, corresponds to the memory location `0xd3e030`, and the value at that location is `5`. When we refer to `x`, we get the corresponding value. Hence, `x` is `5`.
|
|
|
type: Plain text
|
|
|
|
(no translation yet)
|
|
|
|
Located in
src/doc/guide-pointers.md:43
|