about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2013-12-23 15:08:23 +0100
committerSimon Sapin <simon.sapin@exyr.org>2014-01-21 15:48:46 -0800
commitaa66b91767ce92c45192ca11718575529d631d21 (patch)
treeb2d27a96f00a2802fdb8db2da3fda830fbfeac30 /src/libstd
parentadd8f9680e2214c0e44978f1c24a62bd342d9a18 (diff)
downloadrust-aa66b91767ce92c45192ca11718575529d631d21.tar.gz
rust-aa66b91767ce92c45192ca11718575529d631d21.zip
[std::vec] Rename .last_opt() to .last(), drop the old .last() behavior
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/vec.rs33
1 files changed, 5 insertions, 28 deletions
diff --git a/src/libstd/vec.rs b/src/libstd/vec.rs
index 983d2def7b5..b3d0e9cb10a 100644
--- a/src/libstd/vec.rs
+++ b/src/libstd/vec.rs
@@ -952,10 +952,8 @@ pub trait ImmutableVector<'a, T> {
     fn init(&self) -> &'a [T];
     /// Returns all but the last `n' elements of a vector
     fn initn(&self, n: uint) -> &'a [T];
-    /// Returns the last element of a vector, failing if the vector is empty.
-    fn last(&self) -> &'a T;
     /// Returns the last element of a vector, or `None` if it is empty.
-    fn last_opt(&self) -> Option<&'a T>;
+    fn last(&self) -> Option<&'a T>;
     /**
      * Apply a function to each element of a vector and return a concatenation
      * of each result vector
@@ -1142,13 +1140,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
     }
 
     #[inline]
-    fn last(&self) -> &'a T {
-        if self.len() == 0 { fail!("last: empty vector") }
-        &self[self.len() - 1]
-    }
-
-    #[inline]
-    fn last_opt(&self) -> Option<&'a T> {
+    fn last(&self) -> Option<&'a T> {
             if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
     }
 
@@ -3116,27 +3108,12 @@ mod tests {
 
     #[test]
     fn test_last() {
-        let mut a = ~[11];
-        assert_eq!(a.last(), &11);
-        a = ~[11, 12];
-        assert_eq!(a.last(), &12);
-    }
-
-    #[test]
-    #[should_fail]
-    fn test_last_empty() {
-        let a: ~[int] = ~[];
-        a.last();
-    }
-
-    #[test]
-    fn test_last_opt() {
         let mut a = ~[];
-        assert_eq!(a.last_opt(), None);
+        assert_eq!(a.last(), None);
         a = ~[11];
-        assert_eq!(a.last_opt().unwrap(), &11);
+        assert_eq!(a.last().unwrap(), &11);
         a = ~[11, 12];
-        assert_eq!(a.last_opt().unwrap(), &12);
+        assert_eq!(a.last().unwrap(), &12);
     }
 
     #[test]