Skip to content

Commit 5d925b2

Browse files
committed
Make vec::view a method too.
1 parent eb35039 commit 5d925b2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/vec.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
16251625
}
16261626

16271627
trait ImmutableVector<T> {
1628+
pure fn view(start: uint, end: uint) -> &[T];
16281629
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
16291630
pure fn iter(f: fn(T));
16301631
pure fn iteri(f: fn(uint, T));
@@ -1647,6 +1648,10 @@ trait ImmutableEqVector<T: Eq> {
16471648

16481649
/// Extension methods for vectors
16491650
impl<T> &[T]: ImmutableVector<T> {
1651+
/// Return a slice that points into another slice.
1652+
pure fn view(start: uint, end: uint) -> &[T] {
1653+
view(self, start, end)
1654+
}
16501655
/// Reduce a vector from right to left
16511656
#[inline]
16521657
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
@@ -2909,17 +2914,14 @@ mod tests {
29092914
assert capacity(v) == 10u;
29102915
}
29112916

2912-
/*
29132917
#[test]
2914-
#[ignore] // region inference doesn't work well enough for this yet.
29152918
fn test_view() {
29162919
let v = ~[1, 2, 3, 4, 5];
2917-
let v = view(v, 1u, 3u);
2920+
let v = v.view(1u, 3u);
29182921
assert(len(v) == 2u);
29192922
assert(v[0] == 2);
29202923
assert(v[1] == 3);
29212924
}
2922-
*/
29232925
}
29242926

29252927
// Local Variables:

0 commit comments

Comments
 (0)