From 8f9a5079732aa22596ad27e4996189e34147fc1d Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Mon, 7 Jan 2013 19:46:45 -0800 Subject: [PATCH] core: add self to all vec methods --- src/libcore/vec.rs | 115 +++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index ae72e425d20..bf3fd8166c2 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1539,94 +1539,96 @@ pub mod traits { } pub trait ConstVector { - pure fn is_empty() -> bool; - pure fn is_not_empty() -> bool; - pure fn len() -> uint; + pure fn is_empty(&self) -> bool; + pure fn is_not_empty(&self) -> bool; + pure fn len(&self) -> uint; } /// Extension methods for vectors impl &[const T]: ConstVector { /// Returns true if a vector contains no elements #[inline] - pure fn is_empty() -> bool { is_empty(self) } + pure fn is_empty(&self) -> bool { is_empty(*self) } /// Returns true if a vector contains some elements #[inline] - pure fn is_not_empty() -> bool { is_not_empty(self) } + pure fn is_not_empty(&self) -> bool { is_not_empty(*self) } /// Returns the length of a vector #[inline] - pure fn len() -> uint { len(self) } + pure fn len(&self) -> uint { len(*self) } } pub trait CopyableVector { - pure fn head() -> T; - pure fn init() -> ~[T]; - pure fn last() -> T; - pure fn slice(start: uint, end: uint) -> ~[T]; - pure fn tail() -> ~[T]; + pure fn head(&self) -> T; + pure fn init(&self) -> ~[T]; + pure fn last(&self) -> T; + pure fn slice(&self, start: uint, end: uint) -> ~[T]; + pure fn tail(&self) -> ~[T]; } /// Extension methods for vectors impl &[const T]: CopyableVector { /// Returns the first element of a vector #[inline] - pure fn head() -> T { head(self) } + pure fn head(&self) -> T { head(*self) } /// Returns all but the last elemnt of a vector #[inline] - pure fn init() -> ~[T] { init(self) } + pure fn init(&self) -> ~[T] { init(*self) } /// Returns the last element of a `v`, failing if the vector is empty. #[inline] - pure fn last() -> T { last(self) } + pure fn last(&self) -> T { last(*self) } /// Returns a copy of the elements from [`start`..`end`) from `v`. #[inline] - pure fn slice(start: uint, end: uint) -> ~[T] { slice(self, start, end) } + pure fn slice(&self, start: uint, end: uint) -> ~[T] { + slice(*self, start, end) + } /// Returns all but the first element of a vector #[inline] - pure fn tail() -> ~[T] { tail(self) } + pure fn tail(&self) -> ~[T] { tail(*self) } } pub trait ImmutableVector { - pure fn view(start: uint, end: uint) -> &self/[T]; - pure fn foldr(z: U, p: fn(t: &T, u: U) -> U) -> U; - pure fn map(f: fn(t: &T) -> U) -> ~[U]; - pure fn mapi(f: fn(uint, t: &T) -> U) -> ~[U]; - fn map_r(f: fn(x: &T) -> U) -> ~[U]; - pure fn alli(f: fn(uint, t: &T) -> bool) -> bool; - pure fn flat_map(f: fn(t: &T) -> ~[U]) -> ~[U]; - pure fn filter_map(f: fn(t: &T) -> Option) -> ~[U]; + pure fn view(&self, start: uint, end: uint) -> &self/[T]; + pure fn foldr(&self, z: U, p: fn(t: &T, u: U) -> U) -> U; + pure fn map(&self, f: fn(t: &T) -> U) -> ~[U]; + pure fn mapi(&self, f: fn(uint, t: &T) -> U) -> ~[U]; + fn map_r(&self, f: fn(x: &T) -> U) -> ~[U]; + pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool; + pure fn flat_map(&self, f: fn(t: &T) -> ~[U]) -> ~[U]; + pure fn filter_map(&self, f: fn(t: &T) -> Option) -> ~[U]; } /// Extension methods for vectors impl &[T]: ImmutableVector { /// Return a slice that points into another slice. #[inline] - pure fn view(start: uint, end: uint) -> &self/[T] { - view(self, start, end) + pure fn view(&self, start: uint, end: uint) -> &self/[T] { + view(*self, start, end) } /// Reduce a vector from right to left #[inline] - pure fn foldr(z: U, p: fn(t: &T, u: U) -> U) -> U { - foldr(self, z, p) + pure fn foldr(&self, z: U, p: fn(t: &T, u: U) -> U) -> U { + foldr(*self, z, p) } /// Apply a function to each element of a vector and return the results #[inline] - pure fn map(f: fn(t: &T) -> U) -> ~[U] { map(self, f) } + pure fn map(&self, f: fn(t: &T) -> U) -> ~[U] { map(*self, f) } /** * Apply a function to the index and value of each element in the vector * and return the results */ - pure fn mapi(f: fn(uint, t: &T) -> U) -> ~[U] { - mapi(self, f) + pure fn mapi(&self, f: fn(uint, t: &T) -> U) -> ~[U] { + mapi(*self, f) } #[inline] - fn map_r(f: fn(x: &T) -> U) -> ~[U] { + fn map_r(&self, f: fn(x: &T) -> U) -> ~[U] { let mut r = ~[]; let mut i = 0; while i < self.len() { @@ -1641,16 +1643,16 @@ impl &[T]: ImmutableVector { * * If the vector is empty, true is returned. */ - pure fn alli(f: fn(uint, t: &T) -> bool) -> bool { - alli(self, f) + pure fn alli(&self, f: fn(uint, t: &T) -> bool) -> bool { + alli(*self, f) } /** * Apply a function to each element of a vector and return a concatenation * of each result vector */ #[inline] - pure fn flat_map(f: fn(t: &T) -> ~[U]) -> ~[U] { - flat_map(self, f) + pure fn flat_map(&self, f: fn(t: &T) -> ~[U]) -> ~[U] { + flat_map(*self, f) } /** * Apply a function to each element of a vector and return the results @@ -1659,16 +1661,17 @@ impl &[T]: ImmutableVector { * the resulting vector. */ #[inline] - pure fn filter_map(f: fn(t: &T) -> Option) -> ~[U] { - filter_map(self, f) + pure fn filter_map(&self, f: fn(t: &T) -> Option) -> ~[U] { + filter_map(*self, f) } + } pub trait ImmutableEqVector { - pure fn position(f: fn(t: &T) -> bool) -> Option; - pure fn position_elem(t: &T) -> Option; - pure fn rposition(f: fn(t: &T) -> bool) -> Option; - pure fn rposition_elem(t: &T) -> Option; + pure fn position(&self, f: fn(t: &T) -> bool) -> Option; + pure fn position_elem(&self, t: &T) -> Option; + pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option; + pure fn rposition_elem(&self, t: &T) -> Option; } impl &[T]: ImmutableEqVector { @@ -1680,14 +1683,14 @@ impl &[T]: ImmutableEqVector { * elements then none is returned. */ #[inline] - pure fn position(f: fn(t: &T) -> bool) -> Option { - position(self, f) + pure fn position(&self, f: fn(t: &T) -> bool) -> Option { + position(*self, f) } /// Find the first index containing a matching value #[inline] - pure fn position_elem(x: &T) -> Option { - position_elem(self, x) + pure fn position_elem(&self, x: &T) -> Option { + position_elem(*self, x) } /** @@ -1698,21 +1701,21 @@ impl &[T]: ImmutableEqVector { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rposition(f: fn(t: &T) -> bool) -> Option { - rposition(self, f) + pure fn rposition(&self, f: fn(t: &T) -> bool) -> Option { + rposition(*self, f) } /// Find the last index containing a matching value #[inline] - pure fn rposition_elem(t: &T) -> Option { - rposition_elem(self, t) + pure fn rposition_elem(&self, t: &T) -> Option { + rposition_elem(*self, t) } } pub trait ImmutableCopyableVector { - pure fn filter(f: fn(t: &T) -> bool) -> ~[T]; + pure fn filter(&self, f: fn(t: &T) -> bool) -> ~[T]; - pure fn rfind(f: fn(t: &T) -> bool) -> Option; + pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option; } /// Extension methods for vectors @@ -1725,8 +1728,8 @@ impl &[T]: ImmutableCopyableVector { * containing only those elements for which `f` returned true. */ #[inline] - pure fn filter(f: fn(t: &T) -> bool) -> ~[T] { - filter(self, f) + pure fn filter(&self, f: fn(t: &T) -> bool) -> ~[T] { + filter(*self, f) } /** @@ -1737,7 +1740,9 @@ impl &[T]: ImmutableCopyableVector { * returned. If `f` matches no elements then none is returned. */ #[inline] - pure fn rfind(f: fn(t: &T) -> bool) -> Option { rfind(self, f) } + pure fn rfind(&self, f: fn(t: &T) -> bool) -> Option { + rfind(*self, f) + } } pub trait OwnedVector {