Add a total version of vec::last that has a precondition

This commit is contained in:
Tim Chevalier 2011-08-30 17:17:42 -07:00
parent 4fc72c2130
commit 9f7ed2f054

View file

@ -97,6 +97,11 @@ fn last<@T>(v: &[mutable? T]) -> option::t<T> {
ret some(v[len(v) - 1u]);
}
/// Returns the last element of a non-empty vector `v`.
fn last_total<@T>(v: &[mutable? T]) : is_not_empty(v) -> T {
ret v[len(v) - 1u];
}
/// Returns a copy of the elements from [`start`..`end`) from `v`.
fn slice<@T>(v: &[mutable? T], start: uint, end: uint) -> [T] {
assert (start <= end);