diff options
| author | bors <bors@rust-lang.org> | 2013-03-05 02:06:50 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-03-05 02:06:50 -0800 |
| commit | eddefbc893f16ddec44dbb6b5be6adf7d84c2b53 (patch) | |
| tree | 4977e2930f39129932167c5ba7fe90cee0d3e684 /src/libcore | |
| parent | 75c5bc90d2d3fb3e495b38c49c7cc96797795c72 (diff) | |
| parent | af645e848713536ac3c0a0c52de7b4d96f96fbc6 (diff) | |
| download | rust-eddefbc893f16ddec44dbb6b5be6adf7d84c2b53.tar.gz rust-eddefbc893f16ddec44dbb6b5be6adf7d84c2b53.zip | |
auto merge of #5212 : thestinger/rust/iter, r=graydon
A small step towards fixing #2827
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/core.rc | 2 | ||||
| -rw-r--r-- | src/libcore/option.rs | 26 | ||||
| -rw-r--r-- | src/libcore/os.rs | 2 | ||||
| -rw-r--r-- | src/libcore/task/spawn.rs | 8 |
4 files changed, 19 insertions, 19 deletions
diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 010e3f8655b..54644281edf 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -132,8 +132,6 @@ pub mod container; /* Common data structures */ pub mod option; -#[path="iter-trait.rs"] #[merge = "iter-trait/option.rs"] -pub mod option_iter; pub mod result; pub mod either; pub mod dvec; diff --git a/src/libcore/option.rs b/src/libcore/option.rs index e5719b599bd..cffb21c6809 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -45,6 +45,7 @@ use cmp::{Eq,Ord}; use kinds::Copy; use util; use num::Zero; +use iter::BaseIter; #[cfg(test)] use ptr; #[cfg(test)] use str; @@ -229,12 +230,6 @@ pub pure fn map_default<T, U>(opt: &r/Option<T>, def: U, } #[inline(always)] -pub pure fn iter<T>(opt: &r/Option<T>, f: fn(x: &r/T)) { - //! Performs an operation on the contained value by reference - match *opt { None => (), Some(ref t) => f(t) } -} - -#[inline(always)] pub pure fn unwrap<T>(opt: Option<T>) -> T { /*! Moves a value out of an option type and returns it. @@ -281,6 +276,19 @@ pub pure fn expect<T>(opt: Option<T>, reason: &str) -> T { } } +impl<T> BaseIter<T> for Option<T> { + /// Performs an operation on the contained value by reference + #[inline(always)] + pure fn each(&self, f: fn(x: &self/T) -> bool) { + match *self { None => (), Some(ref t) => { f(t); } } + } + + #[inline(always)] + pure fn size_hint(&self) -> Option<uint> { + if self.is_some() { Some(1) } else { Some(0) } + } +} + pub impl<T> Option<T> { /// Returns true if the option equals `none` #[inline(always)] @@ -339,10 +347,6 @@ pub impl<T> Option<T> { } } - /// Performs an operation on the contained value by reference - #[inline(always)] - pure fn iter(&self, f: fn(x: &self/T)) { iter(self, f) } - /** Gets an immutable reference to the value inside an option. @@ -476,7 +480,7 @@ fn test_option_dance() { let x = Some(()); let mut y = Some(5); let mut y2 = 0; - do x.iter |_x| { + for x.each |_x| { y2 = swap_unwrap(&mut y); } assert y2 == 5; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 2341ec33115..d6170609250 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -1241,7 +1241,7 @@ mod tests { setenv(~"HOME", ~""); assert os::homedir().is_none(); - oldhome.iter(|s| setenv(~"HOME", *s)); + for oldhome.each |s| { setenv(~"HOME", *s) } } #[test] diff --git a/src/libcore/task/spawn.rs b/src/libcore/task/spawn.rs index 74384ee3d93..75b38d07ece 100644 --- a/src/libcore/task/spawn.rs +++ b/src/libcore/task/spawn.rs @@ -266,7 +266,7 @@ fn each_ancestor(list: &mut AncestorList, * Step 3: Maybe unwind; compute return info for our caller. *##########################################################*/ if need_unwind && !nobe_is_dead { - do bail_opt.iter |bail_blk| { + for bail_opt.each |bail_blk| { do with_parent_tg(&mut nobe.parent_group) |tg_opt| { (*bail_blk)(tg_opt) } @@ -315,7 +315,7 @@ impl Drop for TCB { unsafe { // If we are failing, the whole taskgroup needs to die. if rt::rust_task_is_unwinding(self.me) { - self.notifier.iter(|x| { x.failed = true; }); + for self.notifier.each |x| { x.failed = true; } // Take everybody down with us. do access_group(&self.tasks) |tg| { kill_taskgroup(tg, self.me, self.is_main); @@ -339,9 +339,7 @@ impl Drop for TCB { fn TCB(me: *rust_task, tasks: TaskGroupArc, ancestors: AncestorList, is_main: bool, notifier: Option<AutoNotify>) -> TCB { - - let notifier = notifier; - notifier.iter(|x| { x.failed = false; }); + for notifier.each |x| { x.failed = false; } TCB { me: me, |
