diff options
| author | Gareth Daniel Smith <garethdanielsmith@gmail.com> | 2012-09-18 21:46:53 +0100 |
|---|---|---|
| committer | Gareth Daniel Smith <garethdanielsmith@gmail.com> | 2012-09-18 21:46:53 +0100 |
| commit | 5d925b212e0dcfa3d754f86ba61d8e85d23e54ee (patch) | |
| tree | 3fcd62236d68dde73f5c7c9a27ff68cf4ee52984 | |
| parent | eb35039fe83d6d13b5c7c08fe761ab85374c96d0 (diff) | |
| download | rust-5d925b212e0dcfa3d754f86ba61d8e85d23e54ee.tar.gz rust-5d925b212e0dcfa3d754f86ba61d8e85d23e54ee.zip | |
Make vec::view a method too.
| -rw-r--r-- | src/libcore/vec.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index f6e2d78e16f..9622e3a11b4 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1625,6 +1625,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> { } trait ImmutableVector<T> { + pure fn view(start: uint, end: uint) -> &[T]; pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U; pure fn iter(f: fn(T)); pure fn iteri(f: fn(uint, T)); @@ -1647,6 +1648,10 @@ trait ImmutableEqVector<T: Eq> { /// Extension methods for vectors impl<T> &[T]: ImmutableVector<T> { + /// Return a slice that points into another slice. + pure fn view(start: uint, end: uint) -> &[T] { + view(self, start, end) + } /// Reduce a vector from right to left #[inline] pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) } @@ -2909,17 +2914,14 @@ mod tests { assert capacity(v) == 10u; } -/* #[test] - #[ignore] // region inference doesn't work well enough for this yet. fn test_view() { let v = ~[1, 2, 3, 4, 5]; - let v = view(v, 1u, 3u); + let v = v.view(1u, 3u); assert(len(v) == 2u); assert(v[0] == 2); assert(v[1] == 3); } -*/ } // Local Variables: |
