@@ -942,10 +942,8 @@ pub trait ImmutableVector<'a, T> {
942
942
/// Returns the element of a vector at the given index, or `None` if the
943
943
/// index is out of bounds
944
944
fn get ( & self , index : uint ) -> Option < & ' a T > ;
945
- /// Returns the first element of a vector, failing if the vector is empty.
946
- fn head ( & self ) -> & ' a T ;
947
945
/// Returns the first element of a vector, or `None` if it is empty
948
- fn head_opt ( & self ) -> Option < & ' a T > ;
946
+ fn head ( & self ) -> Option < & ' a T > ;
949
947
/// Returns all but the first element of a vector
950
948
fn tail ( & self ) -> & ' a [ T ] ;
951
949
/// Returns all but the first `n' elements of a vector
@@ -1123,13 +1121,7 @@ impl<'a,T> ImmutableVector<'a, T> for &'a [T] {
1123
1121
}
1124
1122
1125
1123
#[ inline]
1126
- fn head ( & self ) -> & ' a T {
1127
- if self . len ( ) == 0 { fail ! ( "head: empty vector" ) }
1128
- & self [ 0 ]
1129
- }
1130
-
1131
- #[ inline]
1132
- fn head_opt ( & self ) -> Option < & ' a T > {
1124
+ fn head ( & self ) -> Option < & ' a T > {
1133
1125
if self . len ( ) == 0 { None } else { Some ( & self [ 0 ] ) }
1134
1126
}
1135
1127
@@ -3054,27 +3046,12 @@ mod tests {
3054
3046
3055
3047
#[ test]
3056
3048
fn test_head ( ) {
3057
- let mut a = ~[ 11 ] ;
3058
- assert_eq ! ( a. head( ) , & 11 ) ;
3059
- a = ~[ 11 , 12 ] ;
3060
- assert_eq ! ( a. head( ) , & 11 ) ;
3061
- }
3062
-
3063
- #[ test]
3064
- #[ should_fail]
3065
- fn test_head_empty ( ) {
3066
- let a: ~[ int ] = ~[ ] ;
3067
- a. head ( ) ;
3068
- }
3069
-
3070
- #[ test]
3071
- fn test_head_opt ( ) {
3072
3049
let mut a = ~[ ] ;
3073
- assert_eq ! ( a. head_opt ( ) , None ) ;
3050
+ assert_eq ! ( a. head ( ) , None ) ;
3074
3051
a = ~[ 11 ] ;
3075
- assert_eq ! ( a. head_opt ( ) . unwrap( ) , & 11 ) ;
3052
+ assert_eq ! ( a. head ( ) . unwrap( ) , & 11 ) ;
3076
3053
a = ~[ 11 , 12 ] ;
3077
- assert_eq ! ( a. head_opt ( ) . unwrap( ) , & 11 ) ;
3054
+ assert_eq ! ( a. head ( ) . unwrap( ) , & 11 ) ;
3078
3055
}
3079
3056
3080
3057
#[ test]
0 commit comments