]> git.lizzy.rs Git - rust.git/commitdiff
Add a total version of vec::last that has a precondition
authorTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 31 Aug 2011 00:17:42 +0000 (17:17 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Wed, 31 Aug 2011 00:17:42 +0000 (17:17 -0700)
src/lib/vec.rs

index daa1d499d582d8f33b8f228ddd3d7c8b45ea9006..8a20345b864bd75c8cdf4e6e4065e6a176ceff23 100644 (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);