@@ -71,9 +71,9 @@ export permute;
71
71
export windowed;
72
72
export as_buf;
73
73
export as_mut_buf;
74
- export vec_len;
75
74
export unsafe;
76
75
export u8;
76
+ export extensions;
77
77
78
78
#[ abi = "cdecl" ]
79
79
native mod rustrt {
@@ -954,13 +954,180 @@ fn as_mut_buf<E,T>(v: [mut E], f: fn(*mut E) -> T) -> T unsafe {
954
954
let buf = unsafe :: to_ptr ( v) as * mut E ; f ( buf)
955
955
}
956
956
957
- #[ doc = "An extension implementation providing a `len` method" ]
958
- impl vec_len < T > for [ const T ] {
959
- #[ doc = "Return the length of the vector" ]
960
- #[ inline( always) ]
957
+ #[ doc = "Extension methods for vectors" ]
958
+ impl extensions < T > for [ const T ] {
959
+ #[ doc = "
960
+ Return true if a vector contains an element with the given value
961
+ " ]
962
+ #[ inline]
963
+ fn contains ( x : T ) -> bool { contains ( self , x) }
964
+ #[ doc = "Returns the number of elements that are equal to a given value" ]
965
+ #[ inline]
966
+ fn count ( x : T ) -> uint { count ( self , x) }
967
+ #[ doc = "Reduce a vector from left to right" ]
968
+ #[ inline]
969
+ fn foldl < U : copy > ( z : U , p : fn ( U , T ) -> U ) -> U { foldl ( z, self , p) }
970
+ #[ doc = "Reduce a vector from right to left" ]
971
+ #[ inline]
972
+ fn foldr < U : copy > ( z : U , p : fn ( T , U ) -> U ) -> U { foldr ( self , z, p) }
973
+ #[ doc = "Returns true if a vector contains no elements" ]
974
+ #[ inline]
975
+ fn is_empty ( ) -> bool { is_empty ( self ) }
976
+ #[ doc = "Returns true if a vector contains some elements" ]
977
+ #[ inline]
978
+ fn is_not_empty ( ) -> bool { is_not_empty ( self ) }
979
+ #[ doc = "
980
+ Iterates over a vector
981
+
982
+ Iterates over vector `v` and, for each element, calls function `f` with
983
+ the element's value.
984
+ " ]
985
+ #[ inline]
986
+ fn iter ( f : fn ( T ) ) { iter ( self , f) }
987
+ #[ doc = "
988
+ Iterates over a vector's elements and indexes
989
+
990
+ Iterates over vector `v` and, for each element, calls function `f` with
991
+ the element's value and index.
992
+ " ]
993
+ #[ inline]
994
+ fn iteri ( f : fn ( uint , T ) ) { iteri ( self , f) }
995
+ #[ doc = "Returns the length of a vector" ]
996
+ #[ inline]
961
997
fn len ( ) -> uint { len ( self ) }
998
+ #[ doc = "
999
+ Find the first index matching some predicate
1000
+
1001
+ Apply function `f` to each element of `v`. When function `f` returns true
1002
+ then an option containing the index is returned. If `f` matches no
1003
+ elements then none is returned.
1004
+ " ]
1005
+ #[ inline]
1006
+ fn position ( f : fn ( T ) -> bool ) -> option < uint > { position ( self , f) }
1007
+ #[ doc = "Find the first index containing a matching value" ]
1008
+ #[ inline]
1009
+ fn position_elem ( x : T ) -> option < uint > { position_elem ( self , x) }
1010
+ #[ doc = "
1011
+ Iterates over a vector in reverse
1012
+
1013
+ Iterates over vector `v` and, for each element, calls function `f` with
1014
+ the element's value.
1015
+ " ]
1016
+ #[ inline]
1017
+ fn riter ( f : fn ( T ) ) { riter ( self , f) }
1018
+ #[ doc ="
1019
+ Iterates over a vector's elements and indexes in reverse
1020
+
1021
+ Iterates over vector `v` and, for each element, calls function `f` with
1022
+ the element's value and index.
1023
+ " ]
1024
+ #[ inline]
1025
+ fn riteri ( f : fn ( uint , T ) ) { riteri ( self , f) }
1026
+ #[ doc = "
1027
+ Find the last index matching some predicate
1028
+
1029
+ Apply function `f` to each element of `v` in reverse order. When function
1030
+ `f` returns true then an option containing the index is returned. If `f`
1031
+ matches no elements then none is returned.
1032
+ " ]
1033
+ #[ inline]
1034
+ fn rposition ( f : fn ( T ) -> bool ) -> option < uint > { rposition ( self , f) }
1035
+ #[ doc = "Find the last index containing a matching value" ]
1036
+ #[ inline]
1037
+ fn rposition_elem ( x : T ) -> option < uint > { rposition_elem ( self , x) }
1038
+ }
1039
+
1040
+ #[ doc = "Extension methods for vectors" ]
1041
+ impl extensions < T : copy > for [ const T ] {
1042
+ #[ doc = "
1043
+ Search for the first element that matches a given predicate
1044
+
1045
+ Apply function `f` to each element of `v`, starting from the first.
1046
+ When function `f` returns true then an option containing the element
1047
+ is returned. If `f` matches no elements then none is returned.
1048
+ " ]
1049
+ #[ inline]
1050
+ fn find ( f : fn ( T ) -> bool ) -> option < T > { find ( self , f) }
1051
+ #[ doc = "Returns the first element of a vector" ]
1052
+ #[ inline]
1053
+ fn head ( ) -> T { head ( self ) }
1054
+ #[ doc = "Returns all but the last elemnt of a vector" ]
1055
+ #[ inline]
1056
+ fn init ( ) -> [ T ] { init ( self ) }
1057
+ #[ doc = "
1058
+ Returns the last element of a `v`, failing if the vector is empty.
1059
+ " ]
1060
+ #[ inline]
1061
+ fn last ( ) -> T { last ( self ) }
1062
+ #[ doc = "
1063
+ Search for the last element that matches a given predicate
1064
+
1065
+ Apply function `f` to each element of `v` in reverse order. When function
1066
+ `f` returns true then an option containing the element is returned. If `f`
1067
+ matches no elements then none is returned.
1068
+ " ]
1069
+ #[ inline]
1070
+ fn rfind ( f : fn ( T ) -> bool ) -> option < T > { rfind ( self , f) }
1071
+ #[ doc = "Returns a copy of the elements from [`start`..`end`) from `v`." ]
1072
+ #[ inline]
1073
+ fn slice ( start : uint , end : uint ) -> [ T ] { slice ( self , start, end) }
1074
+ #[ doc = "Returns all but the first element of a vector" ]
1075
+ #[ inline]
1076
+ fn tail ( ) -> [ T ] { tail ( self ) }
1077
+ }
1078
+
1079
+ #[ doc = "Extension methods for vectors" ]
1080
+ impl extensions < T > for [ T ] {
1081
+ #[ doc = "
1082
+ Return true if a predicate matches all elements
1083
+
1084
+ If the vector contains no elements then true is returned.
1085
+ " ]
1086
+ #[ inline]
1087
+ fn all ( f : fn ( T ) -> bool ) -> bool { all ( self , f) }
1088
+ #[ doc = "
1089
+ Return true if a predicate matches any elements
1090
+
1091
+ If the vector contains no elements then false is returned.
1092
+ " ]
1093
+ #[ inline]
1094
+ fn any ( f : fn ( T ) -> bool ) -> bool { any ( self , f) }
1095
+ #[ doc = "
1096
+ Apply a function to each element of a vector and return the results
1097
+
1098
+ If function `f` returns `none` then that element is excluded from
1099
+ the resulting vector.
1100
+ " ]
1101
+ #[ inline]
1102
+ fn filter_map < U : copy > ( f : fn ( T ) -> option < U > ) -> [ U ] {
1103
+ filter_map ( self , f)
1104
+ }
1105
+ #[ doc = "
1106
+ Apply a function eo each element of a vector and return a concatenation
1107
+ of each result vector
1108
+ " ]
1109
+ #[ inline]
1110
+ fn flat_map < U > ( f : fn ( T ) -> [ U ] ) -> [ U ] { flat_map ( self , f) }
1111
+ #[ doc = "
1112
+ Apply a function to each element of a vector and return the results
1113
+ " ]
1114
+ #[ inline]
1115
+ fn map < U > ( f : fn ( T ) -> U ) -> [ U ] { map ( self , f) }
962
1116
}
963
1117
1118
+ #[ doc = "Extension methods for vectors" ]
1119
+ impl extensions < T : copy > for [ T ] {
1120
+ #[ doc = "
1121
+ Construct a new vector from the elements of a vector for which some
1122
+ predicate holds.
1123
+
1124
+ Apply function `f` to each element of `v` and return a vector containing
1125
+ only those elements for which `f` returned true.
1126
+ " ]
1127
+ #[ inline]
1128
+ fn filter ( f : fn ( T ) -> bool ) -> [ T ] { filter ( self , f) }
1129
+ }
1130
+
964
1131
#[ doc = "Unsafe operations" ]
965
1132
mod unsafe {
966
1133
// FIXME: This should have crate visibility
0 commit comments