Skip to content

Commit 1c57c1b

Browse files
committed
---
yaml --- r: 1773 b: refs/heads/master c: e56a172 h: refs/heads/master i: 1771: 825d542 v: v3
1 parent 5905f6b commit 1c57c1b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 71de17d38ee8db40e5f50d2ce8986e9676767309
2+
refs/heads/master: e56a1720e4dd35f9143fc0620083b406c797fb9c

trunk/src/lib/_vec.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import option.none;
2+
import option.some;
3+
14
import vbuf = rustrt.vbuf;
25

36
type operator2[T,U,V] = fn(&T, &U) -> V;
@@ -115,6 +118,15 @@ fn print_debug_info[T](vec[mutable? T] v) {
115118
rustrt.vec_print_debug_info[T](v);
116119
}
117120

121+
// Returns the last element of v.
122+
fn last[T](vec[mutable? T] v) -> option.t[T] {
123+
auto l = len[T](v);
124+
if (l == 0u) {
125+
ret none[T];
126+
}
127+
ret some[T](v.(l - 1u));
128+
}
129+
118130
// Returns elements from [start..end) from v.
119131
fn slice[T](vec[mutable? T] v, uint start, uint end) -> vec[T] {
120132
check (start <= end);

0 commit comments

Comments
 (0)