Skip to content

Commit 1880d78

Browse files
committed
libcore: Partially de-export int-template and uint-template
1 parent 52c3cf2 commit 1880d78

File tree

3 files changed

+82
-70
lines changed

3 files changed

+82
-70
lines changed

src/libcore/core.rc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export private;
8383
// Built-in-type support modules
8484

8585
/// Operations and constants for `int`
86+
#[legacy_exports]
8687
#[path = "int-template"]
8788
mod int {
8889
#[legacy_exports];
@@ -94,6 +95,7 @@ mod int {
9495
}
9596

9697
/// Operations and constants for `i8`
98+
#[legacy_exports]
9799
#[path = "int-template"]
98100
mod i8 {
99101
#[legacy_exports];
@@ -103,6 +105,7 @@ mod i8 {
103105
}
104106

105107
/// Operations and constants for `i16`
108+
#[legacy_exports]
106109
#[path = "int-template"]
107110
mod i16 {
108111
#[legacy_exports];
@@ -112,6 +115,7 @@ mod i16 {
112115
}
113116

114117
/// Operations and constants for `i32`
118+
#[legacy_exports]
115119
#[path = "int-template"]
116120
mod i32 {
117121
#[legacy_exports];
@@ -121,6 +125,7 @@ mod i32 {
121125
}
122126

123127
/// Operations and constants for `i64`
128+
#[legacy_exports]
124129
#[path = "int-template"]
125130
mod i64 {
126131
#[legacy_exports];
@@ -130,6 +135,7 @@ mod i64 {
130135
}
131136

132137
/// Operations and constants for `uint`
138+
#[legacy_exports]
133139
#[path = "uint-template"]
134140
mod uint {
135141
#[legacy_exports];
@@ -146,6 +152,7 @@ mod uint {
146152
}
147153

148154
/// Operations and constants for `u8`
155+
#[legacy_exports]
149156
#[path = "uint-template"]
150157
mod u8 {
151158
#[legacy_exports];
@@ -158,6 +165,7 @@ mod u8 {
158165
}
159166

160167
/// Operations and constants for `u16`
168+
#[legacy_exports]
161169
#[path = "uint-template"]
162170
mod u16 {
163171
#[legacy_exports];
@@ -167,6 +175,7 @@ mod u16 {
167175
}
168176

169177
/// Operations and constants for `u32`
178+
#[legacy_exports]
170179
#[path = "uint-template"]
171180
mod u32 {
172181
#[legacy_exports];
@@ -176,6 +185,7 @@ mod u32 {
176185
}
177186

178187
/// Operations and constants for `u64`
188+
#[legacy_exports]
179189
#[path = "uint-template"]
180190
mod u64 {
181191
#[legacy_exports];

src/libcore/int-template.rs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,38 @@ export abs;
1919
export parse_bytes, from_str, to_str, to_str_bytes, str;
2020
export num, ord, eq, times, timesi;
2121
export bits, bytes;
22+
export str;
2223

23-
const bits : uint = inst::bits;
24-
const bytes : uint = (inst::bits / 8);
24+
pub const bits : uint = inst::bits;
25+
pub const bytes : uint = (inst::bits / 8);
2526

26-
const min_value: T = (-1 as T) << (bits - 1);
27-
const max_value: T = min_value - 1 as T;
27+
pub const min_value: T = (-1 as T) << (bits - 1);
28+
pub const max_value: T = min_value - 1 as T;
2829

29-
pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
30-
pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
30+
pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
31+
pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
3132

32-
pure fn add(x: T, y: T) -> T { x + y }
33-
pure fn sub(x: T, y: T) -> T { x - y }
34-
pure fn mul(x: T, y: T) -> T { x * y }
35-
pure fn div(x: T, y: T) -> T { x / y }
36-
pure fn rem(x: T, y: T) -> T { x % y }
33+
pub pure fn add(x: T, y: T) -> T { x + y }
34+
pub pure fn sub(x: T, y: T) -> T { x - y }
35+
pub pure fn mul(x: T, y: T) -> T { x * y }
36+
pub pure fn div(x: T, y: T) -> T { x / y }
37+
pub pure fn rem(x: T, y: T) -> T { x % y }
3738

38-
pure fn lt(x: T, y: T) -> bool { x < y }
39-
pure fn le(x: T, y: T) -> bool { x <= y }
40-
pure fn eq(x: T, y: T) -> bool { x == y }
41-
pure fn ne(x: T, y: T) -> bool { x != y }
42-
pure fn ge(x: T, y: T) -> bool { x >= y }
43-
pure fn gt(x: T, y: T) -> bool { x > y }
39+
pub pure fn lt(x: T, y: T) -> bool { x < y }
40+
pub pure fn le(x: T, y: T) -> bool { x <= y }
41+
pub pure fn eq(x: T, y: T) -> bool { x == y }
42+
pub pure fn ne(x: T, y: T) -> bool { x != y }
43+
pub pure fn ge(x: T, y: T) -> bool { x >= y }
44+
pub pure fn gt(x: T, y: T) -> bool { x > y }
4445

45-
pure fn is_positive(x: T) -> bool { x > 0 as T }
46-
pure fn is_negative(x: T) -> bool { x < 0 as T }
47-
pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
48-
pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
46+
pub pure fn is_positive(x: T) -> bool { x > 0 as T }
47+
pub pure fn is_negative(x: T) -> bool { x < 0 as T }
48+
pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
49+
pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
4950

5051
#[inline(always)]
5152
/// Iterate over the range [`lo`..`hi`)
52-
fn range(lo: T, hi: T, it: fn(T) -> bool) {
53+
pub fn range(lo: T, hi: T, it: fn(T) -> bool) {
5354
let mut i = lo;
5455
while i < hi {
5556
if !it(i) { break }
@@ -58,13 +59,13 @@ fn range(lo: T, hi: T, it: fn(T) -> bool) {
5859
}
5960

6061
/// Computes the bitwise complement
61-
pure fn compl(i: T) -> T {
62+
pub pure fn compl(i: T) -> T {
6263
-1 as T ^ i
6364
}
6465

6566
/// Computes the absolute value
6667
// FIXME: abs should return an unsigned int (#2353)
67-
pure fn abs(i: T) -> T {
68+
pub pure fn abs(i: T) -> T {
6869
if is_negative(i) { -i } else { i }
6970
}
7071

@@ -137,7 +138,7 @@ impl T: iter::TimesIx {
137138
* * buf - A byte buffer
138139
* * radix - The base of the number
139140
*/
140-
fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
141+
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
141142
if vec::len(buf) == 0u { return None; }
142143
let mut i = vec::len(buf) - 1u;
143144
let mut start = 0u;
@@ -160,22 +161,22 @@ fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
160161
}
161162

162163
/// Parse a string to an int
163-
fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
164+
pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
164165

165166
impl T : FromStr {
166167
static fn from_str(s: &str) -> Option<T> { from_str(s) }
167168
}
168169

169170
/// Convert to a string in a given base
170-
fn to_str(n: T, radix: uint) -> ~str {
171+
pub fn to_str(n: T, radix: uint) -> ~str {
171172
do to_str_bytes(n, radix) |slice| {
172173
do vec::as_imm_buf(slice) |p, len| {
173174
unsafe { str::raw::from_buf_len(p, len) }
174175
}
175176
}
176177
}
177178

178-
fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
179+
pub fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
179180
if n < 0 as T {
180181
uint::to_str_bytes(true, -n as uint, radix, f)
181182
} else {
@@ -184,12 +185,12 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
184185
}
185186

186187
/// Convert to a string
187-
fn str(i: T) -> ~str { return to_str(i, 10u); }
188+
pub fn str(i: T) -> ~str { return to_str(i, 10u); }
188189

189190
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
190191
#[test]
191192
#[ignore]
192-
fn test_from_str() {
193+
pub fn test_from_str() {
193194
assert from_str(~"0") == Some(0 as T);
194195
assert from_str(~"3") == Some(3 as T);
195196
assert from_str(~"10") == Some(10 as T);
@@ -209,7 +210,7 @@ fn test_from_str() {
209210
// FIXME: Has alignment issues on windows and 32-bit linux (#2609)
210211
#[test]
211212
#[ignore]
212-
fn test_parse_bytes() {
213+
pub fn test_parse_bytes() {
213214
use str::to_bytes;
214215
assert parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T);
215216
assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T);
@@ -234,7 +235,7 @@ fn test_parse_bytes() {
234235
}
235236

236237
#[test]
237-
fn test_to_str() {
238+
pub fn test_to_str() {
238239
assert (to_str(0 as T, 10u) == ~"0");
239240
assert (to_str(1 as T, 10u) == ~"1");
240241
assert (to_str(-1 as T, 10u) == ~"-1");
@@ -243,7 +244,7 @@ fn test_to_str() {
243244
}
244245

245246
#[test]
246-
fn test_interfaces() {
247+
pub fn test_interfaces() {
247248
fn test<U:num::Num cmp::Eq>(+ten: U) {
248249
assert (ten.to_int() == 10);
249250

@@ -262,7 +263,7 @@ fn test_interfaces() {
262263
}
263264

264265
#[test]
265-
fn test_times() {
266+
pub fn test_times() {
266267
use iter::Times;
267268
let ten = 10 as T;
268269
let mut accum = 0;
@@ -273,7 +274,7 @@ fn test_times() {
273274
#[test]
274275
#[should_fail]
275276
#[ignore(cfg(windows))]
276-
fn test_times_negative() {
277+
pub fn test_times_negative() {
277278
use iter::Times;
278279
for (-10).times { log(error, ~"nope!"); }
279280
}

0 commit comments

Comments
 (0)