Skip to content

Commit be9b047

Browse files
committed
---
yaml --- r: 77815 b: refs/heads/master c: 70bc163 h: refs/heads/master i: 77813: 14d5e77 77811: 52be1f2 77807: 7b7e3b6 v: v3
1 parent 4415df7 commit be9b047

File tree

4 files changed

+23
-161
lines changed

4 files changed

+23
-161
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: a3d18bc95b1639cf3cb967165f7104e2c79893f5
2+
refs/heads/master: 70bc1637b877f52f824b34bbfbf73936d52a628e
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 60fba4d7d677ec098e6a43014132fe99f7547363
55
refs/heads/try: ebfe63cd1c0b5d23f7ea60c69b4fde2e30cfd42a

trunk/doc/tutorial-container.md

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,14 @@ impl Iterator<int> for ZeroStream {
105105
}
106106
~~~
107107
108-
In general, you cannot rely on the behavior of the `next()` method after it has
109-
returned `None`. Some iterators may return `None` forever. Others may behave
110-
differently.
111-
112108
## Container iterators
113109
114110
Containers implement iteration over the contained elements by returning an
115111
iterator object. For example, vector slices several iterators available:
116112
117113
* `iter()` and `rev_iter()`, for immutable references to the elements
118114
* `mut_iter()` and `mut_rev_iter()`, for mutable references to the elements
119-
* `move_iter()` and `move_rev_iter()`, to move the elements out by-value
115+
* `move_iter()` and `move_rev_iter`, to move the elements out by-value
120116
121117
A typical mutable container will implement at least `iter()`, `mut_iter()` and
122118
`move_iter()` along with the reverse variants if it maintains an order.
@@ -153,7 +149,7 @@ let result = xs.iter().fold(0, |accumulator, item| accumulator - *item);
153149
assert_eq!(result, -41);
154150
~~~
155151
156-
Most adaptors return an adaptor object implementing the `Iterator` trait itself:
152+
Some adaptors return an adaptor object implementing the `Iterator` trait itself:
157153
158154
~~~
159155
let xs = [1, 9, 2, 3, 14, 12];
@@ -162,35 +158,6 @@ let sum = xs.iter().chain(ys.iter()).fold(0, |a, b| a + *b);
162158
assert_eq!(sum, 57);
163159
~~~
164160
165-
Some iterator adaptors may return `None` before exhausting the underlying
166-
iterator. Additionally, if these iterator adaptors are called again after
167-
returning `None`, they may call their underlying iterator again even if the
168-
adaptor will continue to return `None` forever. This may not be desired if the
169-
underlying iterator has side-effects.
170-
171-
In order to provide a guarantee about behavior once `None` has been returned, an
172-
iterator adaptor named `fuse()` is provided. This returns an iterator that will
173-
never call its underlying iterator again once `None` has been returned:
174-
175-
~~~
176-
let xs = [1,2,3,4,5];
177-
let mut calls = 0;
178-
let it = xs.iter().scan((), |_, x| {
179-
calls += 1;
180-
if *x < 3 { Some(x) } else { None }});
181-
// the iterator will only yield 1 and 2 before returning None
182-
// If we were to call it 5 times, calls would end up as 5, despite only 2 values
183-
// being yielded (and therefore 3 unique calls being made). The fuse() adaptor
184-
// can fix this.
185-
let mut it = it.fuse();
186-
it.next();
187-
it.next();
188-
it.next();
189-
it.next();
190-
it.next();
191-
assert_eq!(calls, 3);
192-
~~~
193-
194161
## For loops
195162
196163
The function `range` (or `range_inclusive`) allows to simply iterate through a given range:

trunk/src/etc/emacs/rust-mode.el

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,28 @@
5757
;; A closing brace is 1 level unindended
5858
((looking-at "}") (* rust-indent-offset (- level 1)))
5959

60+
; Doc comments in /** style with leading * indent to line up the *s
61+
((and (nth 4 (syntax-ppss)) (looking-at "*"))
62+
(+ 1 (* rust-indent-offset level)))
63+
6064
;; If we're in any other token-tree / sexp, then:
6165
;; - [ or ( means line up with the opening token
6266
;; - { means indent to either nesting-level * rust-indent-offset,
6367
;; or one further indent from that if either current line
6468
;; begins with 'else', or previous line didn't end in
65-
;; semi, comma or brace, and wasn't an attribute. PHEW.
69+
;; semi, comma or brace (other than whitespace and line
70+
;; comments) , and wasn't an attribute. PHEW.
6671
((> level 0)
6772
(let ((pt (point)))
6873
(rust-rewind-irrelevant)
6974
(backward-up-list)
70-
(if (looking-at "[[(]")
75+
(if (and
76+
(looking-at "[[(]")
77+
; We don't want to indent out to the open bracket if the
78+
; open bracket ends the line
79+
(save-excursion
80+
(forward-char)
81+
(not (looking-at "[[:space:]]*\\(?://.*\\)?$"))))
7182
(+ 1 (current-column))
7283
(progn
7384
(goto-char pt)
@@ -79,7 +90,7 @@
7990
(beginning-of-line)
8091
(rust-rewind-irrelevant)
8192
(end-of-line)
82-
(if (looking-back "[{};,]")
93+
(if (looking-back "[,;{}(][[:space:]]*\\(?://.*\\)?")
8394
(* rust-indent-offset level)
8495
(back-to-indentation)
8596
(if (looking-at "#")

trunk/src/libstd/iterator.rs

Lines changed: 6 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,6 @@ pub trait Extendable<A>: FromIterator<A> {
4141
/// An interface for dealing with "external iterators". These types of iterators
4242
/// can be resumed at any time as all state is stored internally as opposed to
4343
/// being located on the call stack.
44-
///
45-
/// The Iterator protocol states that an iterator yields a (potentially-empty,
46-
/// potentially-infinite) sequence of values, and returns `None` to signal that
47-
/// it's finished. The Iterator protocol does not define behavior after `None`
48-
/// is returned. A concrete Iterator implementation may choose to behave however
49-
/// it wishes, either by returning `None` infinitely, or by doing something
50-
/// else.
5144
pub trait Iterator<A> {
5245
/// Advance the iterator and return the next value. Return `None` when the end is reached.
5346
fn next(&mut self) -> Option<A>;
@@ -307,36 +300,6 @@ pub trait Iterator<A> {
307300
FlatMap{iter: self, f: f, frontiter: None, backiter: None }
308301
}
309302

310-
/// Creates an iterator that yields `None` forever after the underlying
311-
/// iterator yields `None`. Random-access iterator behavior is not
312-
/// affected, only single and double-ended iterator behavior.
313-
///
314-
/// # Example
315-
///
316-
/// ~~~ {.rust}
317-
/// fn process<U: Iterator<int>>(it: U) -> int {
318-
/// let mut it = it.fuse();
319-
/// let mut sum = 0;
320-
/// for x in it {
321-
/// if x > 5 {
322-
/// break;
323-
/// }
324-
/// sum += x;
325-
/// }
326-
/// // did we exhaust the iterator?
327-
/// if it.next().is_none() {
328-
/// sum += 1000;
329-
/// }
330-
/// sum
331-
/// }
332-
/// let x = ~[1,2,3,7,8,9];
333-
/// assert_eq!(process(x.move_iter()), 1006);
334-
/// ~~~
335-
#[inline]
336-
fn fuse(self) -> Fuse<Self> {
337-
Fuse{iter: self, done: false}
338-
}
339-
340303
/// Creates an iterator that calls a function with a reference to each
341304
/// element before yielding it. This is often useful for debugging an
342305
/// iterator pipeline.
@@ -929,12 +892,9 @@ pub struct Zip<T, U> {
929892
impl<A, B, T: Iterator<A>, U: Iterator<B>> Iterator<(A, B)> for Zip<T, U> {
930893
#[inline]
931894
fn next(&mut self) -> Option<(A, B)> {
932-
match self.a.next() {
933-
None => None,
934-
Some(x) => match self.b.next() {
935-
None => None,
936-
Some(y) => Some((x, y))
937-
}
895+
match (self.a.next(), self.b.next()) {
896+
(Some(x), Some(y)) => Some((x, y)),
897+
_ => None
938898
}
939899
}
940900

@@ -965,12 +925,9 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
965925

966926
#[inline]
967927
fn idx(&self, index: uint) -> Option<(A, B)> {
968-
match self.a.idx(index) {
969-
None => None,
970-
Some(x) => match self.b.idx(index) {
971-
None => None,
972-
Some(y) => Some((x, y))
973-
}
928+
match (self.a.idx(index), self.b.idx(index)) {
929+
(Some(x), Some(y)) => Some((x, y)),
930+
_ => None
974931
}
975932
}
976933
}
@@ -1464,79 +1421,6 @@ impl<'self,
14641421
}
14651422
}
14661423

1467-
/// An iterator that yields `None` forever after the underlying iterator
1468-
/// yields `None` once.
1469-
#[deriving(Clone, DeepClone)]
1470-
pub struct Fuse<T> {
1471-
priv iter: T,
1472-
priv done: bool
1473-
}
1474-
1475-
impl<A, T: Iterator<A>> Iterator<A> for Fuse<T> {
1476-
#[inline]
1477-
fn next(&mut self) -> Option<A> {
1478-
if self.done {
1479-
None
1480-
} else {
1481-
match self.iter.next() {
1482-
None => {
1483-
self.done = true;
1484-
None
1485-
}
1486-
x => x
1487-
}
1488-
}
1489-
}
1490-
1491-
#[inline]
1492-
fn size_hint(&self) -> (uint, Option<uint>) {
1493-
if self.done {
1494-
(0, Some(0))
1495-
} else {
1496-
self.iter.size_hint()
1497-
}
1498-
}
1499-
}
1500-
1501-
impl<A, T: DoubleEndedIterator<A>> DoubleEndedIterator<A> for Fuse<T> {
1502-
#[inline]
1503-
fn next_back(&mut self) -> Option<A> {
1504-
if self.done {
1505-
None
1506-
} else {
1507-
match self.iter.next_back() {
1508-
None => {
1509-
self.done = true;
1510-
None
1511-
}
1512-
x => x
1513-
}
1514-
}
1515-
}
1516-
}
1517-
1518-
// Allow RandomAccessIterators to be fused without affecting random-access behavior
1519-
impl<A, T: RandomAccessIterator<A>> RandomAccessIterator<A> for Fuse<T> {
1520-
#[inline]
1521-
fn indexable(&self) -> uint {
1522-
self.iter.indexable()
1523-
}
1524-
1525-
#[inline]
1526-
fn idx(&self, index: uint) -> Option<A> {
1527-
self.iter.idx(index)
1528-
}
1529-
}
1530-
1531-
impl<T> Fuse<T> {
1532-
/// Resets the fuse such that the next call to .next() or .next_back() will
1533-
/// call the underlying iterator again even if it prevously returned None.
1534-
#[inline]
1535-
fn reset_fuse(&mut self) {
1536-
self.done = false
1537-
}
1538-
}
1539-
15401424
/// An iterator that calls a function with a reference to each
15411425
/// element before yielding it.
15421426
pub struct Inspect<'self, A, T> {

0 commit comments

Comments
 (0)