diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index a0516116bdfc..4bc445943cc2 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -1526,6 +1526,7 @@ impl &[const T]: CopyableVector { } trait ImmutableVector { + pure fn view(start: uint, end: uint) -> &[T]; pure fn foldr(z: U, p: fn(T, U) -> U) -> U; pure fn map(f: fn(v: &T) -> U) -> ~[U]; pure fn mapi(f: fn(uint, v: &T) -> U) -> ~[U]; @@ -1544,6 +1545,10 @@ trait ImmutableEqVector { /// Extension methods for vectors impl &[T]: ImmutableVector { + /// 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(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: