Navigation Menu

Skip to content

Commit

Permalink
tutorial: clearer explanation of freezing.
Browse files Browse the repository at this point in the history
- "Lending an immutable pointer" might be confusing. It was not discussed why borrowed pointers are immutable in the first place.
- Make it clear that the borrowed pointers are immutable even if the variable was declared with `mut`.
- Make it clear that we cannot even assign anything to the variable while its value is being borrowed.

tutorial: change "--" to an em-dash.

tutorial: change instances of "--" to em-dash.
  • Loading branch information
Jag Talon committed Feb 25, 2014
1 parent 043c972 commit 82747ed
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/doc/tutorial.md
Expand Up @@ -1468,14 +1468,14 @@ For a more in-depth explanation of references and lifetimes, read the

## Freezing

Lending an immutable pointer to an object freezes it and prevents mutation.
Lending an &-pointer to an object freezes it and prevents mutation—even if the object was declared as `mut`.
`Freeze` objects have freezing enforced statically at compile-time. An example
of a non-`Freeze` type is [`RefCell<T>`][refcell].

~~~~
let mut x = 5;
{
let y = &x; // `x` is now frozen, it cannot be modified
let y = &x; // `x` is now frozen. It cannot be modified or re-assigned.
}
// `x` is now unfrozen again
# x = 3;
Expand Down Expand Up @@ -2021,8 +2021,8 @@ C++ templates.

## Traits

Within a generic function -- that is, a function parameterized by a
type parameter, say, `T` -- the operations we can do on arguments of
Within a generic functionthat is, a function parameterized by a
type parameter, say, `T`the operations we can do on arguments of
type `T` are quite limited. After all, since we don't know what type
`T` will be instantiated with, we can't safely modify or query values
of type `T`. This is where _traits_ come into play. Traits are Rust's
Expand Down

9 comments on commit 82747ed

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jagtalon/rust/jag/rust/tutorial-freezing = 82747ed into auto

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jagtalon/rust/jag/rust/tutorial-freezing = 82747ed merged ok, testing candidate = 3216df86

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging jagtalon/rust/jag/rust/tutorial-freezing = 82747ed into auto

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jagtalon/rust/jag/rust/tutorial-freezing = 82747ed merged ok, testing candidate = 6c41f99

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 82747ed Feb 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6c41f99

Please sign in to comment.