From 4e1fac89bb3e757801735ba6220ddf756054e071 Mon Sep 17 00:00:00 2001 From: gifnksm Date: Tue, 14 May 2013 18:10:50 +0900 Subject: [PATCH] Move `position` and `rposition` methods to `ImmutableVector` trait --- src/libcore/vec.rs | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 21c3dac16f6..be903413ace 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -2069,6 +2069,8 @@ pub trait ImmutableVector<'self, T> { fn initn(&self, n: uint) -> &'self [T]; fn last(&self) -> &'self T; fn last_opt(&self) -> Option<&'self T>; + fn position(&self, f: &fn(t: &T) -> bool) -> Option; + fn rposition(&self, f: &fn(t: &T) -> bool) -> Option; #[cfg(stage0)] fn each_reverse(&self, blk: &fn(&T) -> bool); #[cfg(not(stage0))] @@ -2136,6 +2138,30 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { #[inline] fn last_opt(&self) -> Option<&'self T> { last_opt(*self) } + /** + * Find the first index matching some predicate + * + * Apply function `f` to each element of `v`. When function `f` returns + * true then an option containing the index is returned. If `f` matches no + * elements then none is returned. + */ + #[inline] + fn position(&self, f: &fn(t: &T) -> bool) -> Option { + position(*self, f) + } + + /** + * Find the last index matching some predicate + * + * Apply function `f` to each element of `v` in reverse order. When + * function `f` returns true then an option containing the index is + * returned. If `f` matches no elements then none is returned. + */ + #[inline] + fn rposition(&self, f: &fn(t: &T) -> bool) -> Option { + rposition(*self, f) + } + /// Iterates over a vector's elements in reverse. #[inline] #[cfg(stage0)] @@ -2228,43 +2254,17 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] { } pub trait ImmutableEqVector { - fn position(&self, f: &fn(t: &T) -> bool) -> Option; fn position_elem(&self, t: &T) -> Option; - fn rposition(&self, f: &fn(t: &T) -> bool) -> Option; fn rposition_elem(&self, t: &T) -> Option; } impl<'self,T:Eq> ImmutableEqVector for &'self [T] { - /** - * Find the first index matching some predicate - * - * Apply function `f` to each element of `v`. When function `f` returns - * true then an option containing the index is returned. If `f` matches no - * elements then none is returned. - */ - #[inline] - fn position(&self, f: &fn(t: &T) -> bool) -> Option { - position(*self, f) - } - /// Find the first index containing a matching value #[inline] fn position_elem(&self, x: &T) -> Option { position_elem(*self, x) } - /** - * Find the last index matching some predicate - * - * Apply function `f` to each element of `v` in reverse order. When - * function `f` returns true then an option containing the index is - * returned. If `f` matches no elements then none is returned. - */ - #[inline] - fn rposition(&self, f: &fn(t: &T) -> bool) -> Option { - rposition(*self, f) - } - /// Find the last index containing a matching value #[inline] fn rposition_elem(&self, t: &T) -> Option {