Skip to content

Commit 39f114d

Browse files
committed
De-export iter and result. Part of #3583.
1 parent 24fbf88 commit 39f114d

File tree

3 files changed

+62
-53
lines changed

3 files changed

+62
-53
lines changed

src/libcore/core.rc

-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ mod cmp;
185185
mod num;
186186
mod hash;
187187
mod either;
188-
#[legacy_exports]
189188
mod iter;
190189
mod logging;
191190
mod option;
@@ -194,7 +193,6 @@ mod option_iter {
194193
#[path = "option.rs"]
195194
mod inst;
196195
}
197-
#[legacy_exports]
198196
mod result;
199197
mod to_str;
200198
mod to_bytes;

src/libcore/iter.rs

+42-32
Original file line numberDiff line numberDiff line change
@@ -7,48 +7,49 @@ The iteration traits and common implementation
77
use cmp::{Eq, Ord};
88

99
/// A function used to initialize the elements of a sequence
10-
type InitOp<T> = &fn(uint) -> T;
10+
pub type InitOp<T> = &fn(uint) -> T;
1111

12-
trait BaseIter<A> {
12+
pub trait BaseIter<A> {
1313
pure fn each(blk: fn(v: &A) -> bool);
1414
pure fn size_hint() -> Option<uint>;
1515
}
1616

17-
trait ExtendedIter<A> {
17+
pub trait ExtendedIter<A> {
1818
pure fn eachi(blk: fn(uint, v: &A) -> bool);
1919
pure fn all(blk: fn(&A) -> bool) -> bool;
2020
pure fn any(blk: fn(&A) -> bool) -> bool;
2121
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B;
2222
pure fn position(f: fn(&A) -> bool) -> Option<uint>;
2323
}
2424

25-
trait EqIter<A:Eq> {
25+
pub trait EqIter<A:Eq> {
2626
pure fn contains(x: &A) -> bool;
2727
pure fn count(x: &A) -> uint;
2828
}
2929

30-
trait Times {
30+
pub trait Times {
3131
pure fn times(it: fn() -> bool);
3232
}
33-
trait TimesIx{
33+
34+
pub trait TimesIx{
3435
pure fn timesi(it: fn(uint) -> bool);
3536
}
3637

37-
trait CopyableIter<A:Copy> {
38+
pub trait CopyableIter<A:Copy> {
3839
pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A];
3940
pure fn map_to_vec<B>(op: fn(+v: A) -> B) -> ~[B];
4041
pure fn to_vec() -> ~[A];
4142
pure fn find(p: fn(+a: A) -> bool) -> Option<A>;
4243
}
4344

44-
trait CopyableOrderedIter<A:Copy Ord> {
45+
pub trait CopyableOrderedIter<A:Copy Ord> {
4546
pure fn min() -> A;
4647
pure fn max() -> A;
4748
}
4849

4950
// A trait for sequences that can be by imperatively pushing elements
5051
// onto them.
51-
trait Buildable<A> {
52+
pub trait Buildable<A> {
5253
/**
5354
* Builds a buildable sequence by calling a provided function with
5455
* an argument function that pushes an element onto the back of
@@ -66,38 +67,42 @@ trait Buildable<A> {
6667
builder: fn(push: pure fn(+v: A))) -> self;
6768
}
6869

69-
pure fn eachi<A,IA:BaseIter<A>>(self: &IA, blk: fn(uint, v: &A) -> bool) {
70+
pub pure fn eachi<A,IA:BaseIter<A>>(self: &IA,
71+
blk: fn(uint, v: &A) -> bool) {
7072
let mut i = 0;
7173
for self.each |a| {
7274
if !blk(i, a) { break; }
7375
i += 1;
7476
}
7577
}
7678

77-
pure fn all<A,IA:BaseIter<A>>(self: &IA, blk: fn(&A) -> bool) -> bool {
79+
pub pure fn all<A,IA:BaseIter<A>>(self: &IA,
80+
blk: fn(&A) -> bool) -> bool {
7881
for self.each |a| {
7982
if !blk(a) { return false; }
8083
}
8184
return true;
8285
}
8386

84-
pure fn any<A,IA:BaseIter<A>>(self: &IA, blk: fn(&A) -> bool) -> bool {
87+
pub pure fn any<A,IA:BaseIter<A>>(self: &IA,
88+
blk: fn(&A) -> bool) -> bool {
8589
for self.each |a| {
8690
if blk(a) { return true; }
8791
}
8892
return false;
8993
}
9094

91-
pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(self: &IA,
92-
prd: fn(+a: A) -> bool) -> ~[A] {
95+
pub pure fn filter_to_vec<A:Copy,IA:BaseIter<A>>(
96+
self: &IA, prd: fn(+a: A) -> bool) -> ~[A] {
9397
do vec::build_sized_opt(self.size_hint()) |push| {
9498
for self.each |a| {
9599
if prd(*a) { push(*a); }
96100
}
97101
}
98102
}
99103

100-
pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: &IA, op: fn(+v: A) -> B)
104+
pub pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: &IA,
105+
op: fn(+v: A) -> B)
101106
-> ~[B] {
102107
do vec::build_sized_opt(self.size_hint()) |push| {
103108
for self.each |a| {
@@ -106,7 +111,7 @@ pure fn map_to_vec<A:Copy,B,IA:BaseIter<A>>(self: &IA, op: fn(+v: A) -> B)
106111
}
107112
}
108113

109-
pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
114+
pub pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
110115
self: &IA, op: fn(+a: A) -> IB) -> ~[B] {
111116

112117
do vec::build |push| {
@@ -118,7 +123,8 @@ pure fn flat_map_to_vec<A:Copy,B:Copy,IA:BaseIter<A>,IB:BaseIter<B>>(
118123
}
119124
}
120125

121-
pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, +b0: B, blk: fn(&B, &A) -> B)
126+
pub pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, +b0: B,
127+
blk: fn(&B, &A) -> B)
122128
-> B {
123129
let mut b <- b0;
124130
for self.each |a| {
@@ -127,18 +133,18 @@ pure fn foldl<A,B,IA:BaseIter<A>>(self: &IA, +b0: B, blk: fn(&B, &A) -> B)
127133
move b
128134
}
129135

130-
pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
136+
pub pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
131137
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
132138
}
133139

134-
pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
140+
pub pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
135141
for self.each |a| {
136142
if *a == *x { return true; }
137143
}
138144
return false;
139145
}
140146

141-
pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
147+
pub pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
142148
do foldl(self, 0) |count, value| {
143149
if *value == *x {
144150
*count + 1
@@ -148,7 +154,7 @@ pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
148154
}
149155
}
150156

151-
pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
157+
pub pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
152158
-> Option<uint>
153159
{
154160
let mut i = 0;
@@ -163,15 +169,15 @@ pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
163169
// iter interface, such as would provide "reach" in addition to "each". as is,
164170
// it would have to be implemented with foldr, which is too inefficient.
165171

166-
pure fn repeat(times: uint, blk: fn() -> bool) {
172+
pub pure fn repeat(times: uint, blk: fn() -> bool) {
167173
let mut i = 0;
168174
while i < times {
169175
if !blk() { break }
170176
i += 1;
171177
}
172178
}
173179

174-
pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
180+
pub pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
175181
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
176182
match a {
177183
&Some(ref a_) if *a_ < *b => {
@@ -185,7 +191,7 @@ pure fn min<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
185191
}
186192
}
187193

188-
pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
194+
pub pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
189195
match do foldl::<A,Option<A>,IA>(self, None) |a, b| {
190196
match a {
191197
&Some(ref a_) if *a_ > *b => {
@@ -199,7 +205,7 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
199205
}
200206
}
201207

202-
pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
208+
pub pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
203209
p: fn(+a: A) -> bool) -> Option<A> {
204210
for self.each |i| {
205211
if p(*i) { return Some(*i) }
@@ -220,7 +226,8 @@ pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
220226
* onto the sequence being constructed.
221227
*/
222228
#[inline(always)]
223-
pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(+v: A))) -> B {
229+
pub pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(+v: A)))
230+
-> B {
224231
build_sized(4, builder)
225232
}
226233

@@ -238,7 +245,7 @@ pure fn build<A,B: Buildable<A>>(builder: fn(push: pure fn(+v: A))) -> B {
238245
* onto the sequence being constructed.
239246
*/
240247
#[inline(always)]
241-
pure fn build_sized_opt<A,B: Buildable<A>>(
248+
pub pure fn build_sized_opt<A,B: Buildable<A>>(
242249
size: Option<uint>,
243250
builder: fn(push: pure fn(+v: A))) -> B {
244251

@@ -248,7 +255,8 @@ pure fn build_sized_opt<A,B: Buildable<A>>(
248255
// Functions that combine iteration and building
249256

250257
/// Apply a function to each element of an iterable and return the results
251-
fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: fn(&T) -> U) -> BU {
258+
pub fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: fn(&T) -> U)
259+
-> BU {
252260
do build_sized_opt(v.size_hint()) |push| {
253261
for v.each() |elem| {
254262
push(f(elem));
@@ -262,7 +270,8 @@ fn map<T,IT: BaseIter<T>,U,BU: Buildable<U>>(v: &IT, f: fn(&T) -> U) -> BU {
262270
* Creates a generic sequence of size `n_elts` and initializes the elements
263271
* to the value returned by the function `op`.
264272
*/
265-
pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
273+
pub pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint,
274+
op: InitOp<T>) -> BT {
266275
do build_sized(n_elts) |push| {
267276
let mut i: uint = 0u;
268277
while i < n_elts { push(op(i)); i += 1u; }
@@ -275,7 +284,8 @@ pure fn from_fn<T,BT: Buildable<T>>(n_elts: uint, op: InitOp<T>) -> BT {
275284
* Creates an immutable vector of size `n_elts` and initializes the elements
276285
* to the value `t`.
277286
*/
278-
pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint, +t: T) -> BT {
287+
pub pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint,
288+
+t: T) -> BT {
279289
do build_sized(n_elts) |push| {
280290
let mut i: uint = 0;
281291
while i < n_elts { push(t); i += 1; }
@@ -284,7 +294,7 @@ pure fn from_elem<T: Copy,BT: Buildable<T>>(n_elts: uint, +t: T) -> BT {
284294

285295
/// Appending two generic sequences
286296
#[inline(always)]
287-
pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
297+
pub pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
288298
lhs: &IT, rhs: &IT) -> BT {
289299
let size_opt = lhs.size_hint().chain_ref(
290300
|sz1| rhs.size_hint().map(|sz2| *sz1+*sz2));
@@ -297,7 +307,7 @@ pure fn append<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
297307
/// Copies a generic sequence, possibly converting it to a different
298308
/// type of sequence.
299309
#[inline(always)]
300-
pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
310+
pub pure fn copy_seq<T: Copy,IT: BaseIter<T>,BT: Buildable<T>>(
301311
v: &IT) -> BT {
302312
do build_sized_opt(v.size_hint()) |push| {
303313
for v.each |x| { push(*x); }

0 commit comments

Comments
 (0)