Skip to content

Commit 8055f32

Browse files
committed
---
yaml --- r: 13306 b: refs/heads/master c: 0d20717 h: refs/heads/master v: v3
1 parent 9fb9fb3 commit 8055f32

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 45680c83ab81986bbedf93878e3d24f69be02981
2+
refs/heads/master: 0d20717fab410cf1f90938d90ad4153b77b6f8b3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libcore/dvec.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ fn dvec<A>() -> dvec<A> {
5757
{mut data: [mut]}
5858
}
5959

60+
#[doc = "Creates a new dvec with a single element"]
61+
fn from_elt<A>(+e: A) -> dvec<A> {
62+
{mut data: [mut e]}
63+
}
64+
6065
#[doc = "Creates a new dvec with the contents of a vector"]
6166
fn from_vec<A>(+v: [mut A]) -> dvec<A> {
6267
{mut data: v}
@@ -234,12 +239,19 @@ impl extensions<A:copy> for dvec<A> {
234239
self.data[idx] = a;
235240
}
236241

237-
#[doc = "Overwrites the contents of the element at `idx` with `a`"]
242+
#[doc = "Overwrites the contents of the element at `idx` with `a`,
243+
growing the vector if necessary. New elements will be initialized
244+
with `initval`"]
238245
fn grow_set_elt(idx: uint, initval: A, val: A) {
239246
self.swap { |v|
240247
let mut v <- v;
241248
vec::grow_set(v, idx, initval, val);
242249
v
243250
}
244251
}
252+
253+
#[doc = "Returns the last element, failing if the vector is empty"]
254+
fn last() -> A {
255+
self.get_elt(self.len() - 1u)
256+
}
245257
}

trunk/src/libcore/vec.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,18 @@ fn from_mut<T>(+v: [mut T]) -> [T] unsafe {
211211
pure fn head<T: copy>(v: [const T]/&) -> T { v[0] }
212212

213213
#[doc = "Returns a vector containing all but the first element of a slice"]
214-
fn tail<T: copy>(v: [const T]/&) -> [T] {
214+
pure fn tail<T: copy>(v: [const T]/&) -> [T] {
215215
ret slice(v, 1u, len(v));
216216
}
217217

218218
#[doc = "Returns a vector containing all but the first `n` \
219219
elements of a slice"]
220-
fn tailn<T: copy>(v: [const T]/&, n: uint) -> [T] {
220+
pure fn tailn<T: copy>(v: [const T]/&, n: uint) -> [T] {
221221
slice(v, n, len(v))
222222
}
223223

224224
#[doc = "Returns a vector containing all but the last element of a slice"]
225-
fn init<T: copy>(v: [const T]/&) -> [T] {
225+
pure fn init<T: copy>(v: [const T]/&) -> [T] {
226226
assert len(v) != 0u;
227227
slice(v, 0u, len(v) - 1u)
228228
}
@@ -1033,10 +1033,10 @@ pure fn unpack_mut_slice<T,U>(s: [mut T]/&,
10331033
impl extensions/&<T> for [const T]/& {
10341034
#[doc = "Returns true if a vector contains no elements"]
10351035
#[inline]
1036-
fn is_empty() -> bool { is_empty(self) }
1036+
pure fn is_empty() -> bool { is_empty(self) }
10371037
#[doc = "Returns true if a vector contains some elements"]
10381038
#[inline]
1039-
fn is_not_empty() -> bool { is_not_empty(self) }
1039+
pure fn is_not_empty() -> bool { is_not_empty(self) }
10401040
#[doc = "Returns the length of a vector"]
10411041
#[inline]
10421042
pure fn len() -> uint { len(self) }
@@ -1046,44 +1046,44 @@ impl extensions/&<T> for [const T]/& {
10461046
impl extensions/&<T: copy> for [const T]/& {
10471047
#[doc = "Returns the first element of a vector"]
10481048
#[inline]
1049-
fn head() -> T { head(self) }
1049+
pure fn head() -> T { head(self) }
10501050
#[doc = "Returns all but the last elemnt of a vector"]
10511051
#[inline]
1052-
fn init() -> [T] { init(self) }
1052+
pure fn init() -> [T] { init(self) }
10531053
#[doc = "
10541054
Returns the last element of a `v`, failing if the vector is empty.
10551055
"]
10561056
#[inline]
1057-
fn last() -> T { last(self) }
1057+
pure fn last() -> T { last(self) }
10581058
#[doc = "Returns a copy of the elements from [`start`..`end`) from `v`."]
10591059
#[inline]
1060-
fn slice(start: uint, end: uint) -> [T] { slice(self, start, end) }
1060+
pure fn slice(start: uint, end: uint) -> [T] { slice(self, start, end) }
10611061
#[doc = "Returns all but the first element of a vector"]
10621062
#[inline]
1063-
fn tail() -> [T] { tail(self) }
1063+
pure fn tail() -> [T] { tail(self) }
10641064
}
10651065

10661066
#[doc = "Extension methods for vectors"]
10671067
impl extensions/&<T> for [T]/& {
10681068
#[doc = "Reduce a vector from right to left"]
10691069
#[inline]
1070-
fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
1070+
pure fn foldr<U: copy>(z: U, p: fn(T, U) -> U) -> U { foldr(self, z, p) }
10711071
#[doc = "
10721072
Iterates over a vector
10731073
10741074
Iterates over vector `v` and, for each element, calls function `f` with
10751075
the element's value.
10761076
"]
10771077
#[inline]
1078-
fn iter(f: fn(T)) { iter(self, f) }
1078+
pure fn iter(f: fn(T)) { iter(self, f) }
10791079
#[doc = "
10801080
Iterates over a vector's elements and indexes
10811081
10821082
Iterates over vector `v` and, for each element, calls function `f` with
10831083
the element's value and index.
10841084
"]
10851085
#[inline]
1086-
fn iteri(f: fn(uint, T)) { iteri(self, f) }
1086+
pure fn iteri(f: fn(uint, T)) { iteri(self, f) }
10871087
#[doc = "
10881088
Find the first index matching some predicate
10891089
@@ -1092,26 +1092,26 @@ impl extensions/&<T> for [T]/& {
10921092
elements then none is returned.
10931093
"]
10941094
#[inline]
1095-
fn position(f: fn(T) -> bool) -> option<uint> { position(self, f) }
1095+
pure fn position(f: fn(T) -> bool) -> option<uint> { position(self, f) }
10961096
#[doc = "Find the first index containing a matching value"]
10971097
#[inline]
1098-
fn position_elem(x: T) -> option<uint> { position_elem(self, x) }
1098+
pure fn position_elem(x: T) -> option<uint> { position_elem(self, x) }
10991099
#[doc = "
11001100
Iterates over a vector in reverse
11011101
11021102
Iterates over vector `v` and, for each element, calls function `f` with
11031103
the element's value.
11041104
"]
11051105
#[inline]
1106-
fn riter(f: fn(T)) { riter(self, f) }
1106+
pure fn riter(f: fn(T)) { riter(self, f) }
11071107
#[doc ="
11081108
Iterates over a vector's elements and indexes in reverse
11091109
11101110
Iterates over vector `v` and, for each element, calls function `f` with
11111111
the element's value and index.
11121112
"]
11131113
#[inline]
1114-
fn riteri(f: fn(uint, T)) { riteri(self, f) }
1114+
pure fn riteri(f: fn(uint, T)) { riteri(self, f) }
11151115
#[doc = "
11161116
Find the last index matching some predicate
11171117
@@ -1120,20 +1120,20 @@ impl extensions/&<T> for [T]/& {
11201120
matches no elements then none is returned.
11211121
"]
11221122
#[inline]
1123-
fn rposition(f: fn(T) -> bool) -> option<uint> { rposition(self, f) }
1123+
pure fn rposition(f: fn(T) -> bool) -> option<uint> { rposition(self, f) }
11241124
#[doc = "Find the last index containing a matching value"]
11251125
#[inline]
1126-
fn rposition_elem(x: T) -> option<uint> { rposition_elem(self, x) }
1126+
pure fn rposition_elem(x: T) -> option<uint> { rposition_elem(self, x) }
11271127
#[doc = "
11281128
Apply a function to each element of a vector and return the results
11291129
"]
11301130
#[inline]
1131-
fn map<U>(f: fn(T) -> U) -> [U] { map(self, f) }
1131+
pure fn map<U>(f: fn(T) -> U) -> [U] { map(self, f) }
11321132
#[doc = "
11331133
Apply a function to the index and value of each element in the vector
11341134
and return the results
11351135
"]
1136-
fn mapi<U>(f: fn(uint, T) -> U) -> [U] {
1136+
pure fn mapi<U>(f: fn(uint, T) -> U) -> [U] {
11371137
mapi(self, f)
11381138
}
11391139
#[doc = "Returns true if the function returns true for all elements.
@@ -1147,15 +1147,15 @@ impl extensions/&<T> for [T]/& {
11471147
of each result vector
11481148
"]
11491149
#[inline]
1150-
fn flat_map<U>(f: fn(T) -> [U]) -> [U] { flat_map(self, f) }
1150+
pure fn flat_map<U>(f: fn(T) -> [U]) -> [U] { flat_map(self, f) }
11511151
#[doc = "
11521152
Apply a function to each element of a vector and return the results
11531153
11541154
If function `f` returns `none` then that element is excluded from
11551155
the resulting vector.
11561156
"]
11571157
#[inline]
1158-
fn filter_map<U: copy>(f: fn(T) -> option<U>) -> [U] {
1158+
pure fn filter_map<U: copy>(f: fn(T) -> option<U>) -> [U] {
11591159
filter_map(self, f)
11601160
}
11611161
}
@@ -1170,7 +1170,7 @@ impl extensions/&<T: copy> for [T]/& {
11701170
only those elements for which `f` returned true.
11711171
"]
11721172
#[inline]
1173-
fn filter(f: fn(T) -> bool) -> [T] { filter(self, f) }
1173+
pure fn filter(f: fn(T) -> bool) -> [T] { filter(self, f) }
11741174
#[doc = "
11751175
Search for the first element that matches a given predicate
11761176
@@ -1179,7 +1179,7 @@ impl extensions/&<T: copy> for [T]/& {
11791179
is returned. If `f` matches no elements then none is returned.
11801180
"]
11811181
#[inline]
1182-
fn find(f: fn(T) -> bool) -> option<T> { find(self, f) }
1182+
pure fn find(f: fn(T) -> bool) -> option<T> { find(self, f) }
11831183
#[doc = "
11841184
Search for the last element that matches a given predicate
11851185
@@ -1188,7 +1188,7 @@ impl extensions/&<T: copy> for [T]/& {
11881188
matches no elements then none is returned.
11891189
"]
11901190
#[inline]
1191-
fn rfind(f: fn(T) -> bool) -> option<T> { rfind(self, f) }
1191+
pure fn rfind(f: fn(T) -> bool) -> option<T> { rfind(self, f) }
11921192
}
11931193

11941194
#[doc = "Unsafe operations"]

0 commit comments

Comments
 (0)