aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorJeffrey Yasskin <[email protected]>2010-07-12 05:51:02 +0800
committerGraydon Hoare <[email protected]>2010-07-16 08:13:08 +0800
commit765a2b3ecffb68a18849de6db54a680a1fd6eee4 (patch)
tree98f7e50eb0645feba63432e0ea584f876e212b73 /src/lib
parentAdd a test for std._vec.init_elt, and an XFAILed test for std._vec.init_fn. (diff)
downloadrust-765a2b3ecffb68a18849de6db54a680a1fd6eee4.tar.xz
rust-765a2b3ecffb68a18849de6db54a680a1fd6eee4.zip
Add a _vec.slice function that'll hold us over until .(a,b) syntax is
implemented. This could actually replace .(a,b) syntax if the language grows optional function parameters.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/_vec.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs
index 06e738f5..1b9f5aaa 100644
--- a/src/lib/_vec.rs
+++ b/src/lib/_vec.rs
@@ -48,6 +48,21 @@ fn buf[T](vec[T] v) -> vbuf {
ret rustrt.vec_buf[T](v);
}
+// Returns elements from [start..end) from v.
+fn slice[T](vec[T] v, int start, int end) -> vec[T] {
+ check(0 <= start);
+ check(start <= end);
+ // FIXME #108: This doesn't work yet.
+ //check(end <= int(len[T](v)));
+ auto result = alloc[T](uint(end - start));
+ let mutable int i = start;
+ while (i < end) {
+ result += vec(v.(i));
+ i += 1;
+ }
+ ret result;
+}
+
// Ought to take mutable &vec[T] v and just mutate it instead of copy
// and return. Blocking on issue #89 for this.
fn grow[T](mutable vec[T] v, int n, T initval) -> vec[T] {