Skip to content

Commit f889dd3

Browse files
committed
---
yaml --- r: 67247 b: refs/heads/master c: 4b9759e h: refs/heads/master i: 67245: ca46955 67243: d5a8c59 67239: aeb0abe 67231: ef59723 v: v3
1 parent 5465043 commit f889dd3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
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: 89c4af0ea959dd911eb4a2fe18b9f1e95ef77b8c
2+
refs/heads/master: 4b9759e20fc8a23b3d87765ebb8943adc357ce33
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/libstd/iterator.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ pub trait IteratorUtil<A> {
333333
/// ~~~
334334
fn collect<B: FromIterator<A, Self>>(&mut self) -> B;
335335

336+
/// Loops through the entire iterator, collecting all of the elements into
337+
/// a unique vector. This is simply collect() specialized for vectors.
338+
///
339+
/// # Example
340+
///
341+
/// ~~~ {.rust}
342+
/// let a = [1, 2, 3, 4, 5];
343+
/// let b: ~[int] = a.iter().transform(|&x| x).to_owned_vec();
344+
/// assert!(a == b);
345+
/// ~~~
346+
fn to_owned_vec(&mut self) -> ~[A];
347+
336348
/// Loops through `n` iterations, returning the `n`th element of the
337349
/// iterator.
338350
///
@@ -529,6 +541,11 @@ impl<A, T: Iterator<A>> IteratorUtil<A> for T {
529541
FromIterator::from_iterator(self)
530542
}
531543

544+
#[inline]
545+
fn to_owned_vec(&mut self) -> ~[A] {
546+
self.collect()
547+
}
548+
532549
/// Return the `n`th item yielded by an iterator.
533550
#[inline]
534551
fn nth(&mut self, mut n: uint) -> Option<A> {

0 commit comments

Comments
 (0)