Skip to content

Commit

Permalink
don't say 'semantic'
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed Sep 10, 2014
1 parent 8f7470d commit c3943b3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/doc/guide.md
Expand Up @@ -4271,14 +4271,14 @@ for num in nums.iter() {
}
```

There are two reasons for this. First, this is more semantic. We iterate
through the entire vector, rather than iterating through indexes, and then
indexing the vector. Second, this version is more efficient: the first version
will have extra bounds checking because it used indexing, `nums[i]`. But since
we yield a reference to each element of the vector in turn with the iterator,
there's no bounds checking in the second example. This is very common with
iterators: we can ignore unnecessary bounds checks, but still know that we're
safe.
There are two reasons for this. First, this more directly expresses what we
mean. We iterate through the entire vector, rather than iterating through
indexes, and then indexing the vector. Second, this version is more efficient:
the first version will have extra bounds checking because it used indexing,
`nums[i]`. But since we yield a reference to each element of the vector in turn
with the iterator, there's no bounds checking in the second example. This is
very common with iterators: we can ignore unnecessary bounds checks, but still
know that we're safe.

There's another detail here that's not 100% clear because of how `println!`
works. `num` is actually of type `&int`, that is, it's a reference to an `int`,
Expand Down

9 comments on commit c3943b3

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

saw approval from brson
at steveklabnik@c3943b3

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

merging steveklabnik/rust/dherman_fixes = c3943b3 into auto

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

steveklabnik/rust/dherman_fixes = c3943b3 merged ok, testing candidate = b718e974

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

saw approval from brson
at steveklabnik@c3943b3

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

merging steveklabnik/rust/dherman_fixes = c3943b3 into auto

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 12, 2014

Choose a reason for hiding this comment

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

steveklabnik/rust/dherman_fixes = c3943b3 merged ok, testing candidate = ccae356

@bors
Copy link
Contributor

@bors bors commented on c3943b3 Sep 13, 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 c3943b3 Sep 13, 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 = ccae356

Please sign in to comment.