Skip to content

Commit 8bd22d3

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 163244 b: refs/heads/snap-stage3 c: 1646d10 h: refs/heads/master v: v3
1 parent fa0ddf4 commit 8bd22d3

File tree

3 files changed

+29
-18
lines changed

3 files changed

+29
-18
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 9146a919b616e39e528e4d7100d16eef52f1f852
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 19524f1ed14d8da8b3d953812a3c3b461085d3dc
4+
refs/heads/snap-stage3: 1646d10edc57ec82536d6253f866084beb69a73e
55
refs/heads/try: 20cbbffeefc1f35e2ea63afce7b42fbd79611d42
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcore/iter.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use cmp::Ord;
6262
use kinds::Copy;
6363
use mem;
6464
use num::{ToPrimitive, Int};
65-
use ops::{Add, Deref};
65+
use ops::{Add, Deref, FnMut};
6666
use option::Option;
6767
use option::Option::{Some, None};
6868
use uint;
@@ -165,7 +165,7 @@ pub trait IteratorExt<A>: Iterator<A> {
165165
/// ```
166166
#[inline]
167167
#[unstable = "waiting for unboxed closures"]
168-
fn map<'r, B>(self, f: |A|: 'r -> B) -> Map<'r, A, B, Self> {
168+
fn map<B, F: FnMut(A) -> B>(self, f: F) -> Map<A, B, Self, F> {
169169
Map{iter: self, f: f}
170170
}
171171

@@ -778,7 +778,10 @@ impl<'a, A, T: ExactSizeIterator<A>> ExactSizeIterator<A> for Inspect<'a, A, T>
778778
#[unstable = "trait is unstable"]
779779
impl<A, T: ExactSizeIterator<A>> ExactSizeIterator<A> for Rev<T> {}
780780
#[unstable = "trait is unstable"]
781-
impl<'a, A, B, T: ExactSizeIterator<A>> ExactSizeIterator<B> for Map<'a, A, B, T> {}
781+
impl<A, B, I, F> ExactSizeIterator<B> for Map<A, B, I, F> where
782+
I: ExactSizeIterator<A>,
783+
F: FnMut(A) -> B,
784+
{}
782785
#[unstable = "trait is unstable"]
783786
impl<A, B, T, U> ExactSizeIterator<(A, B)> for Zip<T, U>
784787
where T: ExactSizeIterator<A>, U: ExactSizeIterator<B> {}
@@ -1374,12 +1377,12 @@ RandomAccessIterator<(A, B)> for Zip<T, U> {
13741377
/// An iterator which maps the values of `iter` with `f`
13751378
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
13761379
#[stable]
1377-
pub struct Map<'a, A, B, T> {
1378-
iter: T,
1379-
f: |A|: 'a -> B
1380+
pub struct Map<A, B, I: Iterator<A>, F: FnMut(A) -> B> {
1381+
iter: I,
1382+
f: F,
13801383
}
13811384

1382-
impl<'a, A, B, T> Map<'a, A, B, T> {
1385+
impl<A, B, I, F> Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
13831386
#[inline]
13841387
fn do_map(&mut self, elt: Option<A>) -> Option<B> {
13851388
match elt {
@@ -1390,7 +1393,7 @@ impl<'a, A, B, T> Map<'a, A, B, T> {
13901393
}
13911394

13921395
#[unstable = "trait is unstable"]
1393-
impl<'a, A, B, T: Iterator<A>> Iterator<B> for Map<'a, A, B, T> {
1396+
impl<A, B, I, F> Iterator<B> for Map<A, B, I, F> where I: Iterator<A>, F: FnMut(A) -> B {
13941397
#[inline]
13951398
fn next(&mut self) -> Option<B> {
13961399
let next = self.iter.next();
@@ -1404,7 +1407,10 @@ impl<'a, A, B, T: Iterator<A>> Iterator<B> for Map<'a, A, B, T> {
14041407
}
14051408

14061409
#[unstable = "trait is unstable"]
1407-
impl<'a, A, B, T: DoubleEndedIterator<A>> DoubleEndedIterator<B> for Map<'a, A, B, T> {
1410+
impl<A, B, I, F> DoubleEndedIterator<B> for Map<A, B, I, F> where
1411+
I: DoubleEndedIterator<A>,
1412+
F: FnMut(A) -> B,
1413+
{
14081414
#[inline]
14091415
fn next_back(&mut self) -> Option<B> {
14101416
let next = self.iter.next_back();
@@ -1413,7 +1419,10 @@ impl<'a, A, B, T: DoubleEndedIterator<A>> DoubleEndedIterator<B> for Map<'a, A,
14131419
}
14141420

14151421
#[experimental = "trait is experimental"]
1416-
impl<'a, A, B, T: RandomAccessIterator<A>> RandomAccessIterator<B> for Map<'a, A, B, T> {
1422+
impl<A, B, I, F> RandomAccessIterator<B> for Map<A, B, I, F> where
1423+
I: RandomAccessIterator<A>,
1424+
F: FnMut(A) -> B,
1425+
{
14171426
#[inline]
14181427
fn indexable(&self) -> uint {
14191428
self.iter.indexable()

branches/snap-stage3/src/libcore/str.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,7 @@ impl<'a> DoubleEndedIterator<(uint, char)> for CharOffsets<'a> {
323323

324324
/// External iterator for a string's bytes.
325325
/// Use with the `std::iter` module.
326-
pub type Bytes<'a> =
327-
Map<'a, &'a u8, u8, slice::Items<'a, u8>>;
326+
pub type Bytes<'a> = Map<&'a u8, u8, slice::Items<'a, u8>, fn(&u8) -> u8>;
328327

329328
/// An iterator over the substrings of a string, separated by `sep`.
330329
#[deriving(Clone)]
@@ -349,8 +348,7 @@ pub struct CharSplitsN<'a, Sep> {
349348
}
350349

351350
/// An iterator over the lines of a string, separated by either `\n` or (`\r\n`).
352-
pub type AnyLines<'a> =
353-
Map<'a, &'a str, &'a str, CharSplits<'a, char>>;
351+
pub type AnyLines<'a> = Map<&'a str, &'a str, CharSplits<'a, char>, fn(&str) -> &str>;
354352

355353
impl<'a, Sep> CharSplits<'a, Sep> {
356354
#[inline]
@@ -1980,7 +1978,9 @@ impl StrPrelude for str {
19801978

19811979
#[inline]
19821980
fn bytes(&self) -> Bytes {
1983-
self.as_bytes().iter().map(|&b| b)
1981+
fn deref(&x: &u8) -> u8 { x }
1982+
1983+
self.as_bytes().iter().map(deref)
19841984
}
19851985

19861986
#[inline]
@@ -2053,11 +2053,13 @@ impl StrPrelude for str {
20532053
}
20542054

20552055
fn lines_any(&self) -> AnyLines {
2056-
self.lines().map(|line| {
2056+
fn f(line: &str) -> &str {
20572057
let l = line.len();
20582058
if l > 0 && line.as_bytes()[l - 1] == b'\r' { line.slice(0, l - 1) }
20592059
else { line }
2060-
})
2060+
}
2061+
2062+
self.lines().map(f)
20612063
}
20622064

20632065
#[inline]

0 commit comments

Comments
 (0)