Skip to content

Commit 1229d1c

Browse files
committed
De-export option and option_iter. Part of #3583.
1 parent db44dc5 commit 1229d1c

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

src/libcore/core.rc

-3
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,10 @@ mod either;
190190
#[legacy_exports]
191191
mod iter;
192192
mod logging;
193-
#[legacy_exports]
194193
mod option;
195194
#[path="iter-trait"]
196195
mod option_iter {
197-
#[legacy_exports];
198196
#[path = "option.rs"]
199-
#[legacy_exports]
200197
mod inst;
201198
}
202199
#[legacy_exports]

src/libcore/iter-trait/option.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#[allow(non_camel_case_types)]
2-
type IMPL_T<A> = Option<A>;
2+
pub type IMPL_T<A> = Option<A>;
33

4-
pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
4+
pub pure fn EACH<A>(self: &IMPL_T<A>, f: fn(v: &A) -> bool) {
55
match *self {
66
None => (),
77
Some(ref a) => { f(a); }
88
}
99
}
1010

11-
pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
11+
pub pure fn SIZE_HINT<A>(self: &IMPL_T<A>) -> Option<uint> {
1212
match *self {
1313
None => Some(0),
1414
Some(_) => Some(1)

src/libcore/option.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
use cmp::Eq;
1616

1717
/// The option type
18-
enum Option<T> {
18+
pub enum Option<T> {
1919
None,
2020
Some(T),
2121
}
2222

23-
pure fn get<T: Copy>(opt: &Option<T>) -> T {
23+
pub pure fn get<T: Copy>(opt: &Option<T>) -> T {
2424
/*!
2525
* Gets the value out of an option
2626
*
@@ -35,7 +35,7 @@ pure fn get<T: Copy>(opt: &Option<T>) -> T {
3535
}
3636
}
3737

38-
pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
38+
pub pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
3939
/*!
4040
* Gets an immutable reference to the value inside an option.
4141
*
@@ -49,7 +49,7 @@ pure fn get_ref<T>(opt: &r/Option<T>) -> &r/T {
4949
}
5050
}
5151

52-
pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
52+
pub pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
5353
/*!
5454
* Gets the value out of an option, printing a specified message on
5555
* failure
@@ -61,21 +61,23 @@ pure fn expect<T: Copy>(opt: &Option<T>, +reason: ~str) -> T {
6161
match *opt { Some(copy x) => x, None => fail reason }
6262
}
6363

64-
pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
64+
pub pure fn map<T, U>(opt: &Option<T>, f: fn(x: &T) -> U) -> Option<U> {
6565
//! Maps a `some` value by reference from one type to another
6666
6767
match *opt { Some(ref x) => Some(f(x)), None => None }
6868
}
6969

70-
pure fn map_consume<T, U>(+opt: Option<T>, f: fn(+v: T) -> U) -> Option<U> {
70+
pub pure fn map_consume<T, U>(+opt: Option<T>,
71+
f: fn(+v: T) -> U) -> Option<U> {
7172
/*!
7273
* As `map`, but consumes the option and gives `f` ownership to avoid
7374
* copying.
7475
*/
7576
if opt.is_some() { Some(f(option::unwrap(move opt))) } else { None }
7677
}
7778

78-
pure fn chain<T, U>(+opt: Option<T>, f: fn(+t: T) -> Option<U>) -> Option<U> {
79+
pub pure fn chain<T, U>(+opt: Option<T>,
80+
f: fn(+t: T) -> Option<U>) -> Option<U> {
7981
/*!
8082
* Update an optional value by optionally running its content through a
8183
* function that returns an option.
@@ -89,8 +91,8 @@ pure fn chain<T, U>(+opt: Option<T>, f: fn(+t: T) -> Option<U>) -> Option<U> {
8991
}
9092
}
9193

92-
pure fn chain_ref<T, U>(opt: &Option<T>,
93-
f: fn(x: &T) -> Option<U>) -> Option<U> {
94+
pub pure fn chain_ref<T, U>(opt: &Option<T>,
95+
f: fn(x: &T) -> Option<U>) -> Option<U> {
9496
/*!
9597
* Update an optional value by optionally running its content by reference
9698
* through a function that returns an option.
@@ -99,7 +101,7 @@ pure fn chain_ref<T, U>(opt: &Option<T>,
99101
match *opt { Some(ref x) => f(x), None => None }
100102
}
101103

102-
pure fn or<T>(+opta: Option<T>, +optb: Option<T>) -> Option<T> {
104+
pub pure fn or<T>(+opta: Option<T>, +optb: Option<T>) -> Option<T> {
103105
/*!
104106
* Returns the leftmost some() value, or none if both are none.
105107
*/
@@ -110,7 +112,7 @@ pure fn or<T>(+opta: Option<T>, +optb: Option<T>) -> Option<T> {
110112
}
111113

112114
#[inline(always)]
113-
pure fn while_some<T>(+x: Option<T>, blk: fn(+v: T) -> Option<T>) {
115+
pub pure fn while_some<T>(+x: Option<T>, blk: fn(+v: T) -> Option<T>) {
114116
//! Applies a function zero or more times until the result is none.
115117
116118
let mut opt <- x;
@@ -119,40 +121,40 @@ pure fn while_some<T>(+x: Option<T>, blk: fn(+v: T) -> Option<T>) {
119121
}
120122
}
121123

122-
pure fn is_none<T>(opt: &Option<T>) -> bool {
124+
pub pure fn is_none<T>(opt: &Option<T>) -> bool {
123125
//! Returns true if the option equals `none`
124126
125127
match *opt { None => true, Some(_) => false }
126128
}
127129

128-
pure fn is_some<T>(opt: &Option<T>) -> bool {
130+
pub pure fn is_some<T>(opt: &Option<T>) -> bool {
129131
//! Returns true if the option contains some value
130132
131133
!is_none(opt)
132134
}
133135

134-
pure fn get_default<T: Copy>(opt: &Option<T>, +def: T) -> T {
136+
pub pure fn get_default<T: Copy>(opt: &Option<T>, +def: T) -> T {
135137
//! Returns the contained value or a default
136138
137139
match *opt { Some(copy x) => x, None => def }
138140
}
139141

140-
pure fn map_default<T, U>(opt: &Option<T>, +def: U,
142+
pub pure fn map_default<T, U>(opt: &Option<T>, +def: U,
141143
f: fn(x: &T) -> U) -> U {
142144
//! Applies a function to the contained value or returns a default
143145
144146
match *opt { None => move def, Some(ref t) => f(t) }
145147
}
146148

147-
pure fn iter<T>(opt: &Option<T>, f: fn(x: &T)) {
149+
pub pure fn iter<T>(opt: &Option<T>, f: fn(x: &T)) {
148150
//! Performs an operation on the contained value by reference
149151
match *opt { None => (), Some(ref t) => f(t) }
150152
}
151153

152154
// tjc: shouldn't this be - instead of +?
153155
// then could get rid of some superfluous moves
154156
#[inline(always)]
155-
pure fn unwrap<T>(+opt: Option<T>) -> T {
157+
pub pure fn unwrap<T>(+opt: Option<T>) -> T {
156158
/*!
157159
* Moves a value out of an option type and returns it.
158160
*
@@ -167,12 +169,12 @@ pure fn unwrap<T>(+opt: Option<T>) -> T {
167169

168170
/// The ubiquitous option dance.
169171
#[inline(always)]
170-
fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
172+
pub fn swap_unwrap<T>(opt: &mut Option<T>) -> T {
171173
if opt.is_none() { fail ~"option::swap_unwrap none" }
172174
unwrap(util::replace(opt, None))
173175
}
174176

175-
pure fn unwrap_expect<T>(+opt: Option<T>, reason: &str) -> T {
177+
pub pure fn unwrap_expect<T>(+opt: Option<T>, reason: &str) -> T {
176178
//! As unwrap, but with a specified failure message.
177179
if opt.is_none() { fail reason.to_unique(); }
178180
unwrap(move opt)

0 commit comments

Comments
 (0)