diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-06-21 08:29:53 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-06-23 02:05:20 -0400 |
| commit | d2e9912aea87f9b1812a0f44e093c0405848f7ce (patch) | |
| tree | a872d8f5ab40841274cbb777c642d3b6c9036a87 /src/libstd | |
| parent | c9342663df3e705f6fe380f3d4f46c4a7be8035e (diff) | |
| download | rust-d2e9912aea87f9b1812a0f44e093c0405848f7ce.tar.gz rust-d2e9912aea87f9b1812a0f44e093c0405848f7ce.zip | |
vec: remove BaseIter implementation
I removed the `static-method-test.rs` test because it was heavily based on `BaseIter` and there are plenty of other more complex uses of static methods anyway.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/at_vec.rs | 7 | ||||
| -rw-r--r-- | src/libstd/either.rs | 8 | ||||
| -rw-r--r-- | src/libstd/hash.rs | 7 | ||||
| -rw-r--r-- | src/libstd/hashmap.rs | 5 | ||||
| -rw-r--r-- | src/libstd/io.rs | 18 | ||||
| -rw-r--r-- | src/libstd/iter.rs | 36 | ||||
| -rw-r--r-- | src/libstd/os.rs | 13 | ||||
| -rw-r--r-- | src/libstd/path.rs | 9 | ||||
| -rw-r--r-- | src/libstd/rand.rs | 9 | ||||
| -rw-r--r-- | src/libstd/result.rs | 6 | ||||
| -rw-r--r-- | src/libstd/rt/uv/net.rs | 3 | ||||
| -rw-r--r-- | src/libstd/run.rs | 11 | ||||
| -rw-r--r-- | src/libstd/str.rs | 10 | ||||
| -rw-r--r-- | src/libstd/str/ascii.rs | 3 | ||||
| -rw-r--r-- | src/libstd/to_bytes.rs | 5 | ||||
| -rw-r--r-- | src/libstd/to_str.rs | 8 | ||||
| -rw-r--r-- | src/libstd/trie.rs | 2 | ||||
| -rw-r--r-- | src/libstd/unstable/sync.rs | 2 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 16 |
19 files changed, 88 insertions, 90 deletions
diff --git a/src/libstd/at_vec.rs b/src/libstd/at_vec.rs index 3875847ff9b..2b846c923c4 100644 --- a/src/libstd/at_vec.rs +++ b/src/libstd/at_vec.rs @@ -12,13 +12,14 @@ use cast::transmute; use container::Container; +use iterator::IteratorUtil; use kinds::Copy; use old_iter; -use old_iter::BaseIter; use option::Option; use sys; use uint; use vec; +use vec::ImmutableVector; /// Code for dealing with @-vectors. This is pretty incomplete, and /// contains a bunch of duplication from the code for ~-vectors. @@ -107,7 +108,7 @@ pub fn build_sized_opt<A>(size: Option<uint>, #[inline] pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] { do build_sized(lhs.len() + rhs.len()) |push| { - for lhs.each |x| { push(copy *x); } + for lhs.iter().advance |x| { push(copy *x); } for uint::range(0, rhs.len()) |i| { push(copy rhs[i]); } } } @@ -116,7 +117,7 @@ pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] { /// Apply a function to each element of a vector and return the results pub fn map<T, U>(v: &[T], f: &fn(x: &T) -> U) -> @[U] { do build_sized(v.len()) |push| { - for v.each |elem| { + for v.iter().advance |elem| { push(f(elem)); } } diff --git a/src/libstd/either.rs b/src/libstd/either.rs index 681a7fbc821..b6da93f9d40 100644 --- a/src/libstd/either.rs +++ b/src/libstd/either.rs @@ -15,11 +15,11 @@ use container::Container; use cmp::Eq; use kinds::Copy; -use old_iter::BaseIter; +use iterator::IteratorUtil; use result::Result; use result; use vec; -use vec::OwnedVector; +use vec::{OwnedVector, ImmutableVector}; /// The either type #[deriving(Clone, Eq)] @@ -45,7 +45,7 @@ pub fn either<T, U, V>(f_left: &fn(&T) -> V, /// Extracts from a vector of either all the left values pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] { do vec::build_sized(eithers.len()) |push| { - for eithers.each |elt| { + for eithers.iter().advance |elt| { match *elt { Left(ref l) => { push(copy *l); } _ => { /* fallthrough */ } @@ -57,7 +57,7 @@ pub fn lefts<T:Copy,U>(eithers: &[Either<T, U>]) -> ~[T] { /// Extracts from a vector of either all the right values pub fn rights<T, U: Copy>(eithers: &[Either<T, U>]) -> ~[U] { do vec::build_sized(eithers.len()) |push| { - for eithers.each |elt| { + for eithers.iter().advance |elt| { match *elt { Right(ref r) => { push(copy *r); } _ => { /* fallthrough */ } diff --git a/src/libstd/hash.rs b/src/libstd/hash.rs index 1967a57e867..8e88bfb4632 100644 --- a/src/libstd/hash.rs +++ b/src/libstd/hash.rs @@ -22,10 +22,11 @@ #[allow(missing_doc)]; use container::Container; -use old_iter::BaseIter; +use iterator::IteratorUtil; use rt::io::Writer; use to_bytes::IterBytes; use uint; +use vec::ImmutableVector; // Alias `SipState` to `State`. pub use State = hash::SipState; @@ -367,7 +368,7 @@ impl Streaming for SipState { fn result_str(&mut self) -> ~str { let r = self.result_bytes(); let mut s = ~""; - for r.each |b| { + for r.iter().advance |b| { s += uint::to_str_radix(*b as uint, 16u); } s @@ -469,7 +470,7 @@ mod tests { fn to_hex_str(r: &[u8, ..8]) -> ~str { let mut s = ~""; - for (*r).each |b| { + for r.iter().advance |b| { s += uint::to_str_radix(*b as uint, 16u); } s diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index d05fa63a6f9..02fa2de4b03 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -20,12 +20,13 @@ use cmp::{Eq, Equiv}; use hash::Hash; use old_iter::BaseIter; use old_iter; -use iterator::{IteratorUtil}; +use iterator::IteratorUtil; use option::{None, Option, Some}; use rand::RngUtil; use rand; use uint; use vec; +use vec::ImmutableVector; use kinds::Copy; use util::{replace, unreachable}; @@ -310,7 +311,7 @@ impl<K:Hash + Eq,V> Map<K, V> for HashMap<K, V> { /// Visit all key-value pairs fn each<'a>(&'a self, blk: &fn(&K, &'a V) -> bool) -> bool { - for self.buckets.each |bucket| { + for self.buckets.iter().advance |bucket| { for bucket.iter().advance |pair| { if !blk(&pair.key, &pair.value) { return false; diff --git a/src/libstd/io.rs b/src/libstd/io.rs index 715f2fdabd3..fc0b4da79bd 100644 --- a/src/libstd/io.rs +++ b/src/libstd/io.rs @@ -57,7 +57,7 @@ use os; use cast; use path::Path; use ops::Drop; -use old_iter::{BaseIter, CopyableIter}; +use iterator::IteratorUtil; use ptr; use result; use str; @@ -65,7 +65,7 @@ use str::StrSlice; use to_str::ToStr; use uint; use vec; -use vec::{OwnedVector, OwnedCopyableVector, CopyableVector}; +use vec::{ImmutableVector, OwnedVector, OwnedCopyableVector, CopyableVector}; #[allow(non_camel_case_types)] // not sure what to do about this pub type fd_t = c_int; @@ -1261,7 +1261,7 @@ pub fn mk_file_writer(path: &Path, flags: &[FileFlag]) fn wb() -> c_int { O_WRONLY as c_int } let mut fflags: c_int = wb(); - for flags.each |f| { + for flags.iter().advance |f| { match *f { Append => fflags |= O_APPEND as c_int, Create => fflags |= O_CREAT as c_int, @@ -2015,7 +2015,7 @@ mod tests { // write the ints to the file { let file = io::file_writer(&path, [io::Create]).get(); - for uints.each |i| { + for uints.iter().advance |i| { file.write_le_u64(*i); } } @@ -2023,7 +2023,7 @@ mod tests { // then read them back and check that they are the same { let file = io::file_reader(&path).get(); - for uints.each |i| { + for uints.iter().advance |i| { assert_eq!(file.read_le_u64(), *i); } } @@ -2037,7 +2037,7 @@ mod tests { // write the ints to the file { let file = io::file_writer(&path, [io::Create]).get(); - for uints.each |i| { + for uints.iter().advance |i| { file.write_be_u64(*i); } } @@ -2045,7 +2045,7 @@ mod tests { // then read them back and check that they are the same { let file = io::file_reader(&path).get(); - for uints.each |i| { + for uints.iter().advance |i| { assert_eq!(file.read_be_u64(), *i); } } @@ -2059,7 +2059,7 @@ mod tests { // write the ints to the file { let file = io::file_writer(&path, [io::Create]).get(); - for ints.each |i| { + for ints.iter().advance |i| { file.write_be_i32(*i); } } @@ -2067,7 +2067,7 @@ mod tests { // then read them back and check that they are the same { let file = io::file_reader(&path).get(); - for ints.each |i| { + for ints.iter().advance |i| { // this tests that the sign extension is working // (comparing the values as i32 would not test this) assert_eq!(file.read_be_int_n(4), *i as i64); diff --git a/src/libstd/iter.rs b/src/libstd/iter.rs index 7053cbe0df5..4e598a4aa1c 100644 --- a/src/libstd/iter.rs +++ b/src/libstd/iter.rs @@ -56,7 +56,7 @@ pub trait FromIter<T> { /// /// ~~~ {.rust} /// let xs = ~[1, 2, 3]; - /// let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) }; + /// let ys: ~[int] = do FromIter::from_iter |f| { xs.iter().advance(|x| f(*x)) }; /// assert_eq!(xs, ys); /// ~~~ pub fn from_iter(iter: &fn(f: &fn(T) -> bool) -> bool) -> Self; @@ -69,8 +69,8 @@ pub trait FromIter<T> { * * ~~~ {.rust} * let xs = ~[1u, 2, 3, 4, 5]; - * assert!(any(|&x: &uint| x > 2, |f| xs.each(f))); - * assert!(!any(|&x: &uint| x > 5, |f| xs.each(f))); + * assert!(any(|&x: &uint| x > 2, |f| xs.iter().advance(f))); + * assert!(!any(|&x: &uint| x > 5, |f| xs.iter().advance(f))); * ~~~ */ #[inline] @@ -109,7 +109,7 @@ pub fn all<T>(predicate: &fn(T) -> bool, * * ~~~ {.rust} * let xs = ~[1u, 2, 3, 4, 5, 6]; - * assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4); + * assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.iter().advance(f)).unwrap(), 4); * ~~~ */ #[inline] @@ -130,7 +130,7 @@ pub fn find<T>(predicate: &fn(&T) -> bool, * * ~~~ {.rust} * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; - * assert_eq!(max(|f| xs.each(f)).unwrap(), &15); + * assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &15); * ~~~ */ #[inline] @@ -156,7 +156,7 @@ pub fn max<T: Ord>(iter: &fn(f: &fn(T) -> bool) -> bool) -> Option<T> { * * ~~~ {.rust} * let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; - * assert_eq!(max(|f| xs.each(f)).unwrap(), &-5); + * assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &-5); * ~~~ */ #[inline] @@ -223,7 +223,7 @@ pub fn fold_ref<T, U>(start: T, iter: &fn(f: &fn(&U) -> bool) -> bool, f: &fn(&m * * ~~~ {.rust} * let xs: ~[int] = ~[1, 2, 3, 4]; - * assert_eq!(do sum |f| { xs.each(f) }, 10); + * assert_eq!(do sum |f| { xs.iter().advance(f) }, 10); * ~~~ */ #[inline] @@ -238,7 +238,7 @@ pub fn sum<T: Zero + Add<T, T>>(iter: &fn(f: &fn(&T) -> bool) -> bool) -> T { * * ~~~ {.rust} * let xs: ~[int] = ~[1, 2, 3, 4]; - * assert_eq!(do product |f| { xs.each(f) }, 24); + * assert_eq!(do product |f| { xs.iter().advance(f) }, 24); * ~~~ */ #[inline] @@ -257,15 +257,15 @@ mod tests { #[test] fn test_from_iter() { let xs = ~[1, 2, 3]; - let ys: ~[int] = do FromIter::from_iter |f| { xs.each(|x| f(*x)) }; + let ys: ~[int] = do FromIter::from_iter |f| { xs.iter().advance(|x| f(*x)) }; assert_eq!(xs, ys); } #[test] fn test_any() { let xs = ~[1u, 2, 3, 4, 5]; - assert!(any(|&x: &uint| x > 2, |f| xs.each(f))); - assert!(!any(|&x: &uint| x > 5, |f| xs.each(f))); + assert!(any(|&x: &uint| x > 2, |f| xs.iter().advance(f))); + assert!(!any(|&x: &uint| x > 5, |f| xs.iter().advance(f))); } #[test] @@ -277,19 +277,19 @@ mod tests { #[test] fn test_find() { let xs = ~[1u, 2, 3, 4, 5, 6]; - assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.each(f)).unwrap(), 4); + assert_eq!(*find(|& &x: & &uint| x > 3, |f| xs.iter().advance(f)).unwrap(), 4); } #[test] fn test_max() { let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; - assert_eq!(max(|f| xs.each(f)).unwrap(), &15); + assert_eq!(max(|f| xs.iter().advance(f)).unwrap(), &15); } #[test] fn test_min() { let xs = ~[8, 2, 3, 1, -5, 9, 11, 15]; - assert_eq!(min(|f| xs.each(f)).unwrap(), &-5); + assert_eq!(min(|f| xs.iter().advance(f)).unwrap(), &-5); } #[test] @@ -300,24 +300,24 @@ mod tests { #[test] fn test_sum() { let xs: ~[int] = ~[1, 2, 3, 4]; - assert_eq!(do sum |f| { xs.each(f) }, 10); + assert_eq!(do sum |f| { xs.iter().advance(f) }, 10); } #[test] fn test_empty_sum() { let xs: ~[int] = ~[]; - assert_eq!(do sum |f| { xs.each(f) }, 0); + assert_eq!(do sum |f| { xs.iter().advance(f) }, 0); } #[test] fn test_product() { let xs: ~[int] = ~[1, 2, 3, 4]; - assert_eq!(do product |f| { xs.each(f) }, 24); + assert_eq!(do product |f| { xs.iter().advance(f) }, 24); } #[test] fn test_empty_product() { let xs: ~[int] = ~[]; - assert_eq!(do product |f| { xs.each(f) }, 1); + assert_eq!(do product |f| { xs.iter().advance(f) }, 1); } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 59b40b93d4d..1ceb22b20ca 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -224,7 +224,7 @@ pub fn env() -> ~[(~str,~str)] { fn env_convert(input: ~[~str]) -> ~[(~str, ~str)] { let mut pairs = ~[]; - for input.each |p| { + for input.iter().advance |p| { let vs: ~[&str] = p.splitn_iter('=', 1).collect(); debug!("splitting: len: %u", vs.len()); @@ -593,7 +593,8 @@ pub fn tmpdir() -> Path { /// Recursively walk a directory structure pub fn walk_dir(p: &Path, f: &fn(&Path) -> bool) -> bool { - list_dir(p).each(|q| { + let r = list_dir(p); + r.iter().advance(|q| { let path = &p.push(*q); f(path) && (!path_is_dir(path) || walk_dir(path, f)) }) @@ -1528,7 +1529,7 @@ mod tests { fn test_env_getenv() { let e = env(); assert!(e.len() > 0u); - for e.each |p| { + for e.iter().advance |p| { let (n, v) = copy *p; debug!(copy n); let v2 = getenv(n); @@ -1599,8 +1600,8 @@ mod tests { setenv("USERPROFILE", "/home/PaloAlto"); assert_eq!(os::homedir(), Some(Path("/home/MountainView"))); - oldhome.each(|s| { setenv("HOME", *s); true }); - olduserprofile.each(|s| { setenv("USERPROFILE", *s); true }); + oldhome.iter().advance(|s| { setenv("HOME", *s); true }); + olduserprofile.iter().advance(|s| { setenv("USERPROFILE", *s); true }); } #[test] @@ -1620,7 +1621,7 @@ mod tests { // Just assuming that we've got some contents in the current directory assert!(dirs.len() > 0u); - for dirs.each |dir| { + for dirs.iter().advance |dir| { debug!(copy *dir); } } diff --git a/src/libstd/path.rs b/src/libstd/path.rs index d7812bf49c2..700bfff3f5d 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -25,8 +25,7 @@ use str; use str::{Str, StrSlice, StrVector}; use to_str::ToStr; use ascii::{AsciiCast, AsciiStr}; -use old_iter::BaseIter; -use vec::OwnedVector; +use vec::{OwnedVector, ImmutableVector}; #[cfg(windows)] pub use Path = self::WindowsPath; @@ -596,7 +595,7 @@ impl GenericPath for PosixPath { fn push_many<S: Str>(&self, cs: &[S]) -> PosixPath { let mut v = copy self.components; - for cs.each |e| { + for cs.iter().advance |e| { for e.as_slice().split_iter(windows::is_sep).advance |s| { if !s.is_empty() { v.push(s.to_owned()) @@ -853,7 +852,7 @@ impl GenericPath for WindowsPath { fn push_many<S: Str>(&self, cs: &[S]) -> WindowsPath { let mut v = copy self.components; - for cs.each |e| { + for cs.iter().advance |e| { for e.as_slice().split_iter(windows::is_sep).advance |s| { if !s.is_empty() { v.push(s.to_owned()) @@ -915,7 +914,7 @@ impl GenericPath for WindowsPath { pub fn normalize(components: &[~str]) -> ~[~str] { let mut cs = ~[]; - for components.each |c| { + for components.iter().advance |c| { if *c == ~"." && components.len() > 1 { loop; } if *c == ~"" { loop; } if *c == ~".." && cs.len() != 0 { diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs index 739e3dfedc7..c49e2af2f02 100644 --- a/src/libstd/rand.rs +++ b/src/libstd/rand.rs @@ -544,7 +544,7 @@ impl<R: Rng> RngUtil for R { fn choose_weighted_option<T:Copy>(&mut self, v: &[Weighted<T>]) -> Option<T> { let mut total = 0u; - for v.each |item| { + for v.iter().advance |item| { total += item.weight; } if total == 0u { @@ -552,7 +552,7 @@ impl<R: Rng> RngUtil for R { } let chosen = self.gen_uint_range(0u, total); let mut so_far = 0u; - for v.each |item| { + for v.iter().advance |item| { so_far += item.weight; if so_far > chosen { return Some(copy item.item); @@ -567,7 +567,7 @@ impl<R: Rng> RngUtil for R { */ fn weighted_vec<T:Copy>(&mut self, v: &[Weighted<T>]) -> ~[T] { let mut r = ~[]; - for v.each |item| { + for v.iter().advance |item| { for uint::range(0u, item.weight) |_i| { r.push(copy item.item); } @@ -746,7 +746,8 @@ impl IsaacRng { }} ); - for [(0, midpoint), (midpoint, 0)].each |&(mr_offset, m2_offset)| { + let r = [(0, midpoint), (midpoint, 0)]; + for r.iter().advance |&(mr_offset, m2_offset)| { for uint::range_step(0, midpoint, 4) |base| { rngstep!(0, 13); rngstep!(1, -6); diff --git a/src/libstd/result.rs b/src/libstd/result.rs index 6cef5c33de0..0b099b66ecf 100644 --- a/src/libstd/result.rs +++ b/src/libstd/result.rs @@ -16,10 +16,10 @@ use cmp::Eq; use either; use either::Either; use kinds::Copy; +use iterator::IteratorUtil; use option::{None, Option, Some}; -use old_iter::BaseIter; use vec; -use vec::OwnedVector; +use vec::{OwnedVector, ImmutableVector}; use container::Container; /// The result type @@ -303,7 +303,7 @@ pub fn map_vec<T,U:Copy,V:Copy>( ts: &[T], op: &fn(&T) -> Result<V,U>) -> Result<~[V],U> { let mut vs: ~[V] = vec::with_capacity(ts.len()); - for ts.each |t| { + for ts.iter().advance |t| { match op(t) { Ok(v) => vs.push(v), Err(u) => return Err(u) diff --git a/src/libstd/rt/uv/net.rs b/src/libstd/rt/uv/net.rs index 4571747cebf..ada9aee35a7 100644 --- a/src/libstd/rt/uv/net.rs +++ b/src/libstd/rt/uv/net.rs @@ -389,7 +389,8 @@ mod test { if status.is_none() { rtdebug!("got %d bytes", nread); let buf = buf.unwrap(); - for buf.slice(0, nread as uint).each |byte| { + let r = buf.slice(0, nread as uint); + for r.iter().advance |byte| { assert!(*byte == count as u8); rtdebug!("%u", *byte as uint); count += 1; diff --git a/src/libstd/run.rs b/src/libstd/run.rs index 060de3f4d5d..c965af7c10c 100644 --- a/src/libstd/run.rs +++ b/src/libstd/run.rs @@ -582,7 +582,7 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str { let mut cmd = ~""; append_arg(&mut cmd, prog); - for args.each |arg| { + for args.iter().advance |arg| { cmd.push_char(' '); append_arg(&mut cmd, *arg); } @@ -698,7 +698,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T { let mut argptrs = ~[str::as_c_str(prog, |b| b)]; let mut tmps = ~[]; - for args.each |arg| { + for args.iter().advance |arg| { let t = @copy *arg; tmps.push(t); argptrs.push(str::as_c_str(*t, |b| b)); @@ -716,7 +716,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*c_void) -> T) -> T { let mut tmps = ~[]; let mut ptrs = ~[]; - for es.each |&(k, v)| { + for es.iter().advance |&(k, v)| { let kv = @fmt!("%s=%s", k, v); tmps.push(kv); ptrs.push(str::as_c_str(*kv, |b| b)); @@ -739,7 +739,7 @@ fn with_envp<T>(env: Option<&[(~str, ~str)]>, cb: &fn(*mut c_void) -> T) -> T { match env { Some(es) => { let mut blk = ~[]; - for es.each |&(k, v)| { + for es.iter().advance |&(k, v)| { let kv = fmt!("%s=%s", k, v); blk.push_all(kv.as_bytes_with_null_consume()); } @@ -1165,7 +1165,8 @@ mod tests { let mut prog = run_env(None); let output = str::from_bytes(prog.finish_with_output().output); - for os::env().each |&(k, v)| { + let r = os::env(); + for r.iter().advance |&(k, v)| { // don't check windows magical empty-named variables assert!(k.is_empty() || output.contains(fmt!("%s=%s", k, v))); } diff --git a/src/libstd/str.rs b/src/libstd/str.rs index f3226b27d1b..45ba8528375 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -29,7 +29,7 @@ use iterator::{Iterator, IteratorUtil, FilterIterator, AdditiveIterator, MapIter use libc; use num::Zero; use option::{None, Option, Some}; -use old_iter::{BaseIter, EqIter}; +use old_iter::EqIter; use ptr; use ptr::RawPtr; use to_str::ToStr; @@ -147,7 +147,7 @@ pub fn from_char(ch: char) -> ~str { pub fn from_chars(chs: &[char]) -> ~str { let mut buf = ~""; buf.reserve(chs.len()); - for chs.each |ch| { + for chs.iter().advance |ch| { buf.push_char(*ch) } buf @@ -864,7 +864,7 @@ pub mod raw { unsafe fn push_bytes(s: &mut ~str, bytes: &[u8]) { let new_len = s.len() + bytes.len(); s.reserve_at_least(new_len); - for bytes.each |byte| { push_byte(&mut *s, *byte); } + for bytes.iter().advance |byte| { push_byte(&mut *s, *byte); } } /// Removes the last byte from a string and returns it. (Not UTF-8 safe). @@ -3080,7 +3080,7 @@ mod tests { 0xd801_u16, 0xdc95_u16, 0xd801_u16, 0xdc86_u16, 0x000a_u16 ]) ]; - for pairs.each |p| { + for pairs.iter().advance |p| { let (s, u) = copy *p; assert!(s.to_utf16() == u); assert!(from_utf16(u) == s); @@ -3094,7 +3094,7 @@ mod tests { let s = ~"ศไทย中华Việt Nam"; let v = ~['ศ','ไ','ท','ย','中','华','V','i','ệ','t',' ','N','a','m']; let mut pos = 0; - for v.each |ch| { + for v.iter().advance |ch| { assert!(s.char_at(pos) == *ch); pos += from_char(*ch).len(); } diff --git a/src/libstd/str/ascii.rs b/src/libstd/str/ascii.rs index c71765f911a..d8b50c96fd8 100644 --- a/src/libstd/str/ascii.rs +++ b/src/libstd/str/ascii.rs @@ -14,7 +14,6 @@ use to_str::{ToStr,ToStrConsume}; use str; use str::StrSlice; use cast; -use old_iter::BaseIter; use iterator::IteratorUtil; use vec::{CopyableVector, ImmutableVector, OwnedVector}; use to_bytes::IterBytes; @@ -94,7 +93,7 @@ impl<'self> AsciiCast<&'self[Ascii]> for &'self [u8] { #[inline] fn is_ascii(&self) -> bool { - for self.each |b| { + for self.iter().advance |b| { if !b.is_ascii() { return false; } } true diff --git a/src/libstd/to_bytes.rs b/src/libstd/to_bytes.rs index 822aab0a027..6f0c615d007 100644 --- a/src/libstd/to_bytes.rs +++ b/src/libstd/to_bytes.rs @@ -17,9 +17,10 @@ The `ToBytes` and `IterBytes` traits use cast; use io; use io::Writer; +use iterator::IteratorUtil; use option::{None, Option, Some}; -use old_iter::BaseIter; use str::StrSlice; +use vec::ImmutableVector; pub type Cb<'self> = &'self fn(buf: &[u8]) -> bool; @@ -223,7 +224,7 @@ impl IterBytes for f64 { impl<'self,A:IterBytes> IterBytes for &'self [A] { #[inline] fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool { - self.each(|elt| elt.iter_bytes(lsb0, |b| f(b))) + self.iter().advance(|elt| elt.iter_bytes(lsb0, |b| f(b))) } } diff --git a/src/libstd/to_str.rs b/src/libstd/to_str.rs index 3e782e728fe..c6ac2c89f32 100644 --- a/src/libstd/to_str.rs +++ b/src/libstd/to_str.rs @@ -17,10 +17,12 @@ The `ToStr` trait for converting to strings use str::OwnedStr; use hashmap::HashMap; use hashmap::HashSet; +use iterator::IteratorUtil; use container::Map; use hash::Hash; use cmp::Eq; use old_iter::BaseIter; +use vec::ImmutableVector; /// A generic trait for converting a value to a string pub trait ToStr { @@ -122,7 +124,7 @@ impl<'self,A:ToStr> ToStr for &'self [A] { #[inline] fn to_str(&self) -> ~str { let mut (acc, first) = (~"[", true); - for self.each |elt| { + for self.iter().advance |elt| { if first { first = false; } @@ -140,7 +142,7 @@ impl<A:ToStr> ToStr for ~[A] { #[inline] fn to_str(&self) -> ~str { let mut (acc, first) = (~"[", true); - for self.each |elt| { + for self.iter().advance |elt| { if first { first = false; } @@ -158,7 +160,7 @@ impl<A:ToStr> ToStr for @[A] { #[inline] fn to_str(&self) -> ~str { let mut (acc, first) = (~"[", true); - for self.each |elt| { + for self.iter().advance |elt| { if first { first = false; } diff --git a/src/libstd/trie.rs b/src/libstd/trie.rs index aaeaa489834..39980ffa599 100644 --- a/src/libstd/trie.rs +++ b/src/libstd/trie.rs @@ -373,7 +373,7 @@ pub fn check_integrity<T>(trie: &TrieNode<T>) { let mut sum = 0; - for trie.children.each |x| { + for trie.children.iter().advance |x| { match *x { Nothing => (), Internal(ref y) => { diff --git a/src/libstd/unstable/sync.rs b/src/libstd/unstable/sync.rs index 79aa22fabea..235dfa01849 100644 --- a/src/libstd/unstable/sync.rs +++ b/src/libstd/unstable/sync.rs @@ -237,7 +237,7 @@ mod tests { } }; - for futures.each |f| { f.recv() } + for futures.iter().advance |f| { f.recv() } do total.with |total| { assert!(**total == num_tasks * count) diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index 62b42eebfbb..17eb7e8e82b 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -17,7 +17,6 @@ use cast; use container::{Container, Mutable}; use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering, Less, Equal, Greater}; use clone::Clone; -use old_iter::BaseIter; use old_iter; use iterator::{FromIterator, Iterator, IteratorUtil}; use iter::FromIter; @@ -1025,7 +1024,7 @@ impl<'self, T:Copy> VectorVector<T> for &'self [~[T]] { pub fn connect_vec(&self, sep: &T) -> ~[T] { let mut r = ~[]; let mut first = true; - for self.each |&inner| { + for self.iter().advance |&inner| { if first { first = false; } else { r.push(copy *sep); } r.push_all(inner); } @@ -1043,7 +1042,7 @@ impl<'self, T:Copy> VectorVector<T> for &'self [&'self [T]] { pub fn connect_vec(&self, sep: &T) -> ~[T] { let mut r = ~[]; let mut first = true; - for self.each |&inner| { + for self.iter().advance |&inner| { if first { first = false; } else { r.push(copy *sep); } r.push_all(inner); } @@ -1749,7 +1748,7 @@ impl<'self,T:Copy> CopyableVector<T> for &'self [T] { fn to_owned(&self) -> ~[T] { let mut result = ~[]; reserve(&mut result, self.len()); - for self.each |e| { + for self.iter().advance |e| { result.push(copy *e); } result @@ -2399,15 +2398,6 @@ pub mod bytes { } } -impl<'self,A> old_iter::BaseIter<A> for &'self [A] { - #[inline] - fn each<'a>(&'a self, blk: &fn(v: &'a A) -> bool) -> bool { - each(*self, blk) - } - #[inline] - fn size_hint(&self) -> Option<uint> { Some(self.len()) } -} - impl<A:Clone> Clone for ~[A] { #[inline] fn clone(&self) -> ~[A] { |
