about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <andersrb@gmail.com>2012-09-26 21:08:26 -0700
committerBrian Anderson <andersrb@gmail.com>2012-09-26 21:08:26 -0700
commit2340ef96d54d488c53eeab1967a2347aebde38ca (patch)
tree33708d4b08a74b51dc8ad7b3d432ad0bd1d78780
parent7f7af5f2ceedf533d2d09a1a2afd8b53031e5a9a (diff)
parent5d925b212e0dcfa3d754f86ba61d8e85d23e54ee (diff)
downloadrust-2340ef96d54d488c53eeab1967a2347aebde38ca.tar.gz
rust-2340ef96d54d488c53eeab1967a2347aebde38ca.zip
Merge pull request #3526 from Dretch/viewmethod
Make vec::view a method too.
-rw-r--r--src/libcore/vec.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs
index a0516116bdf..4bc445943cc 100644
--- a/src/libcore/vec.rs
+++ b/src/libcore/vec.rs
@@ -1526,6 +1526,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 map<U>(f: fn(v: &T) -> U) -> ~[U];
     pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U];
@@ -1544,6 +1545,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) }
@@ -2804,17 +2809,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: