We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 71de17d commit e56a172Copy full SHA for e56a172
src/lib/_vec.rs
@@ -1,3 +1,6 @@
1
+import option.none;
2
+import option.some;
3
+
4
import vbuf = rustrt.vbuf;
5
6
type operator2[T,U,V] = fn(&T, &U) -> V;
@@ -115,6 +118,15 @@ fn print_debug_info[T](vec[mutable? T] v) {
115
118
rustrt.vec_print_debug_info[T](v);
116
119
}
117
120
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
130
// Returns elements from [start..end) from v.
131
fn slice[T](vec[mutable? T] v, uint start, uint end) -> vec[T] {
132
check (start <= end);
0 commit comments