diff options
Diffstat (limited to 'src/lib/_vec.rs')
| -rw-r--r-- | src/lib/_vec.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/lib/_vec.rs b/src/lib/_vec.rs new file mode 100644 index 00000000..c938e6fb --- /dev/null +++ b/src/lib/_vec.rs @@ -0,0 +1,30 @@ +import vbuf = rustrt.vbuf; + +native "rust" mod rustrt { + type vbuf; + fn vec_buf[T](vec[T] v) -> vbuf; + fn vec_len[T](vec[T] v) -> uint; + fn vec_alloc[T](int n_elts) -> vec[T]; +} + +fn alloc[T](int n_elts) -> vec[T] { + ret rustrt.vec_alloc[T](n_elts); +} + +fn init[T](&T t, int n_elts) -> vec[T] { + let vec[T] v = alloc[T](n_elts); + let int i = n_elts; + while (i > 0) { + i -= 1; + v += vec(t); + } + ret v; +} + +fn len[T](vec[T] v) -> uint { + ret rustrt.vec_len[T](v); +} + +fn buf[T](vec[T] v) -> vbuf { + ret rustrt.vec_buf[T](v); +} |