Skip to content

Commit 9f7ed2f

Browse files
committed
Add a total version of vec::last that has a precondition
1 parent 4fc72c2 commit 9f7ed2f

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/lib/vec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ fn last<@T>(v: &[mutable? T]) -> option::t<T> {
9797
ret some(v[len(v) - 1u]);
9898
}
9999

100+
/// Returns the last element of a non-empty vector `v`.
101+
fn last_total<@T>(v: &[mutable? T]) : is_not_empty(v) -> T {
102+
ret v[len(v) - 1u];
103+
}
104+
100105
/// Returns a copy of the elements from [`start`..`end`) from `v`.
101106
fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] {
102107
assert (start <= end);

0 commit comments

Comments
 (0)