Skip to content

Commit 2340ef9

Browse files
committed
Merge pull request #3526 from Dretch/viewmethod
Make vec::view a method too.
2 parents 7f7af5f + 5d925b2 commit 2340ef9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/libcore/vec.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,7 @@ impl<T: Copy> &[const T]: CopyableVector<T> {
15261526
}
15271527

15281528
trait ImmutableVector<T> {
1529+
pure fn view(start: uint, end: uint) -> &[T];
15291530
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U;
15301531
pure fn map<U>(f: fn(v: &T) -> U) -> ~[U];
15311532
pure fn mapi<U>(f: fn(uint, v: &T) -> U) -> ~[U];
@@ -1544,6 +1545,10 @@ trait ImmutableEqVector<T: Eq> {
15441545

15451546
/// Extension methods for vectors
15461547
impl<T> &[T]: ImmutableVector<T> {
1548+
/// Return a slice that points into another slice.
1549+
pure fn view(start: uint, end: uint) -> &[T] {
1550+
view(self, start, end)
1551+
}
15471552
/// Reduce a vector from right to left
15481553
#[inline]
15491554
pure fn foldr<U: Copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
@@ -2804,17 +2809,14 @@ mod tests {
28042809
assert capacity(v) == 10u;
28052810
}
28062811

2807-
/*
28082812
#[test]
2809-
#[ignore] // region inference doesn't work well enough for this yet.
28102813
fn test_view() {
28112814
let v = ~[1, 2, 3, 4, 5];
2812-
let v = view(v, 1u, 3u);
2815+
let v = v.view(1u, 3u);
28132816
assert(len(v) == 2u);
28142817
assert(v[0] == 2);
28152818
assert(v[1] == 3);
28162819
}
2817-
*/
28182820
}
28192821

28202822
// Local Variables:

0 commit comments

Comments
 (0)