diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2013-06-19 18:56:57 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2013-06-21 03:24:03 -0400 |
| commit | 06bec77fafb1c30052b9c69a3fb17b2835cb608f (patch) | |
| tree | 720e62a93084d160efa4aa40057558237ce4d76e /src/libstd | |
| parent | 883c966d5c6ba93bf8834543500b01f644ab362f (diff) | |
| download | rust-06bec77fafb1c30052b9c69a3fb17b2835cb608f.tar.gz rust-06bec77fafb1c30052b9c69a3fb17b2835cb608f.zip | |
replace vec::find with the IteratorUtil method
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/vec.rs | 41 |
2 files changed, 1 insertions, 42 deletions
diff --git a/src/libstd/str.rs b/src/libstd/str.rs index fd11b49a00a..f3226b27d1b 100644 --- a/src/libstd/str.rs +++ b/src/libstd/str.rs @@ -60,7 +60,7 @@ pub fn from_bytes(vv: &[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { - let first_bad_byte = vec::find(vv, |b| !is_utf8([*b])).get(); + let first_bad_byte = *vv.iter().find_(|&b| !is_utf8([*b])).get(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs index ce5662c6d4b..703224e37c5 100644 --- a/src/libstd/vec.rs +++ b/src/libstd/vec.rs @@ -1057,17 +1057,6 @@ pub fn contains<T:Eq>(v: &[T], x: &T) -> bool { } /** - * Search for the first element that matches a given predicate - * - * Apply function `f` to each element of `v`, starting from the first. - * When function `f` returns true then an option containing the element - * is returned. If `f` matches no elements then none is returned. - */ -pub fn find<T:Copy>(v: &[T], f: &fn(t: &T) -> bool) -> Option<T> { - find_between(v, 0u, v.len(), f) -} - -/** * Search for the first element that matches a given predicate within a range * * Apply function `f` to each element of `v` within the range @@ -3164,18 +3153,6 @@ mod tests { } #[test] - fn test_find() { - assert!(find([], f).is_none()); - - fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } - fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } - let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; - - assert_eq!(find(v, f), Some((1, 'b'))); - assert!(find(v, g).is_none()); - } - - #[test] fn test_find_between() { assert!(find_between([], 0u, 0u, f).is_none()); @@ -3205,8 +3182,6 @@ mod tests { #[test] fn test_rposition() { - assert!(find([], f).is_none()); - fn f(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'b' } fn g(xy: &(int, char)) -> bool { let (_x, y) = *xy; y == 'd' } let v = ~[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'b')]; @@ -3841,22 +3816,6 @@ mod tests { #[test] #[ignore(windows)] #[should_fail] - #[allow(non_implicitly_copyable_typarams)] - fn test_find_fail() { - let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; - let mut i = 0; - do find(v) |_elt| { - if i == 2 { - fail!() - } - i += 0; - false - }; - } - - #[test] - #[ignore(windows)] - #[should_fail] fn test_rposition_fail() { let v = [(~0, @0), (~0, @0), (~0, @0), (~0, @0)]; let mut i = 0; |
