about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-09-26 18:46:12 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-09-26 18:46:48 -0700
commit1880d783b73387c1baac9e5cb0167d7a0f6e768c (patch)
treeb1249cf0ff781ae208d45c532706a58abeeddff8 /src/libcore
parent52c3cf296b637d66d185c2304f15f65aa55bb484 (diff)
libcore: Partially de-export int-template and uint-template
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/core.rc10
-rw-r--r--src/libcore/int-template.rs71
-rw-r--r--src/libcore/uint-template.rs71
3 files changed, 82 insertions, 70 deletions
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index e82c16b1f04..d3a41d3d395 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -83,6 +83,7 @@ export private;
 // Built-in-type support modules
 
 /// Operations and constants for `int`
+#[legacy_exports]
 #[path = "int-template"]
 mod int {
     #[legacy_exports];
@@ -94,6 +95,7 @@ mod int {
 }
 
 /// Operations and constants for `i8`
+#[legacy_exports]
 #[path = "int-template"]
 mod i8 {
     #[legacy_exports];
@@ -103,6 +105,7 @@ mod i8 {
 }
 
 /// Operations and constants for `i16`
+#[legacy_exports]
 #[path = "int-template"]
 mod i16 {
     #[legacy_exports];
@@ -112,6 +115,7 @@ mod i16 {
 }
 
 /// Operations and constants for `i32`
+#[legacy_exports]
 #[path = "int-template"]
 mod i32 {
     #[legacy_exports];
@@ -121,6 +125,7 @@ mod i32 {
 }
 
 /// Operations and constants for `i64`
+#[legacy_exports]
 #[path = "int-template"]
 mod i64 {
     #[legacy_exports];
@@ -130,6 +135,7 @@ mod i64 {
 }
 
 /// Operations and constants for `uint`
+#[legacy_exports]
 #[path = "uint-template"]
 mod uint {
     #[legacy_exports];
@@ -146,6 +152,7 @@ mod uint {
 }
 
 /// Operations and constants for `u8`
+#[legacy_exports]
 #[path = "uint-template"]
 mod u8 {
     #[legacy_exports];
@@ -158,6 +165,7 @@ mod u8 {
 }
 
 /// Operations and constants for `u16`
+#[legacy_exports]
 #[path = "uint-template"]
 mod u16 {
     #[legacy_exports];
@@ -167,6 +175,7 @@ mod u16 {
 }
 
 /// Operations and constants for `u32`
+#[legacy_exports]
 #[path = "uint-template"]
 mod u32 {
     #[legacy_exports];
@@ -176,6 +185,7 @@ mod u32 {
 }
 
 /// Operations and constants for `u64`
+#[legacy_exports]
 #[path = "uint-template"]
 mod u64 {
     #[legacy_exports];
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index 649400e2360..d24a10be6ce 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -19,37 +19,38 @@ export abs;
 export parse_bytes, from_str, to_str, to_str_bytes, str;
 export num, ord, eq, times, timesi;
 export bits, bytes;
+export str;
 
-const bits : uint = inst::bits;
-const bytes : uint = (inst::bits / 8);
+pub const bits : uint = inst::bits;
+pub const bytes : uint = (inst::bits / 8);
 
-const min_value: T = (-1 as T) << (bits - 1);
-const max_value: T = min_value - 1 as T;
+pub const min_value: T = (-1 as T) << (bits - 1);
+pub const max_value: T = min_value - 1 as T;
 
-pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
-pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
+pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
+pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
 
-pure fn add(x: T, y: T) -> T { x + y }
-pure fn sub(x: T, y: T) -> T { x - y }
-pure fn mul(x: T, y: T) -> T { x * y }
-pure fn div(x: T, y: T) -> T { x / y }
-pure fn rem(x: T, y: T) -> T { x % y }
+pub pure fn add(x: T, y: T) -> T { x + y }
+pub pure fn sub(x: T, y: T) -> T { x - y }
+pub pure fn mul(x: T, y: T) -> T { x * y }
+pub pure fn div(x: T, y: T) -> T { x / y }
+pub pure fn rem(x: T, y: T) -> T { x % y }
 
-pure fn lt(x: T, y: T) -> bool { x < y }
-pure fn le(x: T, y: T) -> bool { x <= y }
-pure fn eq(x: T, y: T) -> bool { x == y }
-pure fn ne(x: T, y: T) -> bool { x != y }
-pure fn ge(x: T, y: T) -> bool { x >= y }
-pure fn gt(x: T, y: T) -> bool { x > y }
+pub pure fn lt(x: T, y: T) -> bool { x < y }
+pub pure fn le(x: T, y: T) -> bool { x <= y }
+pub pure fn eq(x: T, y: T) -> bool { x == y }
+pub pure fn ne(x: T, y: T) -> bool { x != y }
+pub pure fn ge(x: T, y: T) -> bool { x >= y }
+pub pure fn gt(x: T, y: T) -> bool { x > y }
 
-pure fn is_positive(x: T) -> bool { x > 0 as T }
-pure fn is_negative(x: T) -> bool { x < 0 as T }
-pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
-pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
+pub pure fn is_positive(x: T) -> bool { x > 0 as T }
+pub pure fn is_negative(x: T) -> bool { x < 0 as T }
+pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
+pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
 
 #[inline(always)]
 /// Iterate over the range [`lo`..`hi`)
-fn range(lo: T, hi: T, it: fn(T) -> bool) {
+pub fn range(lo: T, hi: T, it: fn(T) -> bool) {
     let mut i = lo;
     while i < hi {
         if !it(i) { break }
@@ -58,13 +59,13 @@ fn range(lo: T, hi: T, it: fn(T) -> bool) {
 }
 
 /// Computes the bitwise complement
-pure fn compl(i: T) -> T {
+pub pure fn compl(i: T) -> T {
     -1 as T ^ i
 }
 
 /// Computes the absolute value
 // FIXME: abs should return an unsigned int (#2353)
-pure fn abs(i: T) -> T {
+pub pure fn abs(i: T) -> T {
     if is_negative(i) { -i } else { i }
 }
 
@@ -137,7 +138,7 @@ impl T: iter::TimesIx {
  * * buf - A byte buffer
  * * radix - The base of the number
  */
-fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
+pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
     if vec::len(buf) == 0u { return None; }
     let mut i = vec::len(buf) - 1u;
     let mut start = 0u;
@@ -160,14 +161,14 @@ fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
 }
 
 /// Parse a string to an int
-fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
+pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
 
 impl T : FromStr {
     static fn from_str(s: &str) -> Option<T> { from_str(s) }
 }
 
 /// Convert to a string in a given base
-fn to_str(n: T, radix: uint) -> ~str {
+pub fn to_str(n: T, radix: uint) -> ~str {
     do to_str_bytes(n, radix) |slice| {
         do vec::as_imm_buf(slice) |p, len| {
             unsafe { str::raw::from_buf_len(p, len) }
@@ -175,7 +176,7 @@ fn to_str(n: T, radix: uint) -> ~str {
     }
 }
 
-fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
+pub fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
     if n < 0 as T {
         uint::to_str_bytes(true, -n as uint, radix, f)
     } else {
@@ -184,12 +185,12 @@ fn to_str_bytes<U>(n: T, radix: uint, f: fn(v: &[u8]) -> U) -> U {
 }
 
 /// Convert to a string
-fn str(i: T) -> ~str { return to_str(i, 10u); }
+pub fn str(i: T) -> ~str { return to_str(i, 10u); }
 
 // FIXME: Has alignment issues on windows and 32-bit linux (#2609)
 #[test]
 #[ignore]
-fn test_from_str() {
+pub fn test_from_str() {
     assert from_str(~"0") == Some(0 as T);
     assert from_str(~"3") == Some(3 as T);
     assert from_str(~"10") == Some(10 as T);
@@ -209,7 +210,7 @@ fn test_from_str() {
 // FIXME: Has alignment issues on windows and 32-bit linux (#2609)
 #[test]
 #[ignore]
-fn test_parse_bytes() {
+pub fn test_parse_bytes() {
     use str::to_bytes;
     assert parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T);
     assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T);
@@ -234,7 +235,7 @@ fn test_parse_bytes() {
 }
 
 #[test]
-fn test_to_str() {
+pub fn test_to_str() {
     assert (to_str(0 as T, 10u) == ~"0");
     assert (to_str(1 as T, 10u) == ~"1");
     assert (to_str(-1 as T, 10u) == ~"-1");
@@ -243,7 +244,7 @@ fn test_to_str() {
 }
 
 #[test]
-fn test_interfaces() {
+pub fn test_interfaces() {
     fn test<U:num::Num cmp::Eq>(+ten: U) {
         assert (ten.to_int() == 10);
 
@@ -262,7 +263,7 @@ fn test_interfaces() {
 }
 
 #[test]
-fn test_times() {
+pub fn test_times() {
     use iter::Times;
     let ten = 10 as T;
     let mut accum = 0;
@@ -273,7 +274,7 @@ fn test_times() {
 #[test]
 #[should_fail]
 #[ignore(cfg(windows))]
-fn test_times_negative() {
+pub fn test_times_negative() {
     use iter::Times;
     for (-10).times { log(error, ~"nope!"); }
 }
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index f5d2229513d..6757946c334 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -18,37 +18,38 @@ export to_str, to_str_bytes;
 export from_str, from_str_radix, str, parse_bytes;
 export num, ord, eq, times, timesi;
 export bits, bytes;
+export str;
 
-const bits : uint = inst::bits;
-const bytes : uint = (inst::bits / 8);
+pub const bits : uint = inst::bits;
+pub const bytes : uint = (inst::bits / 8);
 
-const min_value: T = 0 as T;
-const max_value: T = 0 as T - 1 as T;
+pub const min_value: T = 0 as T;
+pub const max_value: T = 0 as T - 1 as T;
 
-pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
-pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
+pub pure fn min(x: T, y: T) -> T { if x < y { x } else { y } }
+pub pure fn max(x: T, y: T) -> T { if x > y { x } else { y } }
 
-pure fn add(x: T, y: T) -> T { x + y }
-pure fn sub(x: T, y: T) -> T { x - y }
-pure fn mul(x: T, y: T) -> T { x * y }
-pure fn div(x: T, y: T) -> T { x / y }
-pure fn rem(x: T, y: T) -> T { x % y }
+pub pure fn add(x: T, y: T) -> T { x + y }
+pub pure fn sub(x: T, y: T) -> T { x - y }
+pub pure fn mul(x: T, y: T) -> T { x * y }
+pub pure fn div(x: T, y: T) -> T { x / y }
+pub pure fn rem(x: T, y: T) -> T { x % y }
 
-pure fn lt(x: T, y: T) -> bool { x < y }
-pure fn le(x: T, y: T) -> bool { x <= y }
-pure fn eq(x: T, y: T) -> bool { x == y }
-pure fn ne(x: T, y: T) -> bool { x != y }
-pure fn ge(x: T, y: T) -> bool { x >= y }
-pure fn gt(x: T, y: T) -> bool { x > y }
+pub pure fn lt(x: T, y: T) -> bool { x < y }
+pub pure fn le(x: T, y: T) -> bool { x <= y }
+pub pure fn eq(x: T, y: T) -> bool { x == y }
+pub pure fn ne(x: T, y: T) -> bool { x != y }
+pub pure fn ge(x: T, y: T) -> bool { x >= y }
+pub pure fn gt(x: T, y: T) -> bool { x > y }
 
-pure fn is_positive(x: T) -> bool { x > 0 as T }
-pure fn is_negative(x: T) -> bool { x < 0 as T }
-pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
-pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
+pub pure fn is_positive(x: T) -> bool { x > 0 as T }
+pub pure fn is_negative(x: T) -> bool { x < 0 as T }
+pub pure fn is_nonpositive(x: T) -> bool { x <= 0 as T }
+pub pure fn is_nonnegative(x: T) -> bool { x >= 0 as T }
 
 #[inline(always)]
 /// Iterate over the range [`lo`..`hi`)
-pure fn range(lo: T, hi: T, it: fn(T) -> bool) {
+pub pure fn range(lo: T, hi: T, it: fn(T) -> bool) {
     let mut i = lo;
     while i < hi {
         if !it(i) { break }
@@ -57,7 +58,7 @@ pure fn range(lo: T, hi: T, it: fn(T) -> bool) {
 }
 
 /// Computes the bitwise complement
-pure fn compl(i: T) -> T {
+pub pure fn compl(i: T) -> T {
     max_value ^ i
 }
 
@@ -126,7 +127,7 @@ impl T: iter::TimesIx {
  *
  * `buf` must not be empty
  */
-fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
+pub fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
     if vec::len(buf) == 0u { return None; }
     let mut i = vec::len(buf) - 1u;
     let mut power = 1u as T;
@@ -143,14 +144,14 @@ fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
 }
 
 /// Parse a string to an int
-fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
+pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
 
 impl T : FromStr {
     static fn from_str(s: &str) -> Option<T> { from_str(s) }
 }
 
 /// Parse a string as an unsigned integer.
-fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
+pub fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
     if str::len(buf) == 0u { return None; }
     let mut i = str::len(buf) - 1u;
     let mut power = 1u64, n = 0u64;
@@ -172,7 +173,7 @@ fn from_str_radix(buf: &str, radix: u64) -> Option<u64> {
  *
  * Fails if `radix` < 2 or `radix` > 16
  */
-pure fn to_str(num: T, radix: uint) -> ~str {
+pub pure fn to_str(num: T, radix: uint) -> ~str {
     do to_str_bytes(false, num, radix) |slice| {
         do vec::as_imm_buf(slice) |p, len| {
             unsafe { str::raw::from_buf_len(p, len) }
@@ -181,7 +182,7 @@ pure fn to_str(num: T, radix: uint) -> ~str {
 }
 
 /// Low-level helper routine for string conversion.
-pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
+pub pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
                    f: fn(v: &[u8]) -> U) -> U {
 
     #[inline(always)]
@@ -246,10 +247,10 @@ pure fn to_str_bytes<U>(neg: bool, num: T, radix: uint,
 }
 
 /// Convert to a string
-fn str(i: T) -> ~str { return to_str(i, 10u); }
+pub fn str(i: T) -> ~str { return to_str(i, 10u); }
 
 #[test]
-fn test_to_str() {
+pub fn test_to_str() {
     assert to_str(0 as T, 10u) == ~"0";
     assert to_str(1 as T, 10u) == ~"1";
     assert to_str(2 as T, 10u) == ~"2";
@@ -261,7 +262,7 @@ fn test_to_str() {
 
 #[test]
 #[ignore]
-fn test_from_str() {
+pub fn test_from_str() {
     assert from_str(~"0") == Some(0u as T);
     assert from_str(~"3") == Some(3u as T);
     assert from_str(~"10") == Some(10u as T);
@@ -275,7 +276,7 @@ fn test_from_str() {
 
 #[test]
 #[ignore]
-fn test_parse_bytes() {
+pub fn test_parse_bytes() {
     use str::to_bytes;
     assert parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T);
     assert parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T);
@@ -291,19 +292,19 @@ fn test_parse_bytes() {
 #[test]
 #[should_fail]
 #[ignore(cfg(windows))]
-fn to_str_radix1() {
+pub fn to_str_radix1() {
     uint::to_str(100u, 1u);
 }
 
 #[test]
 #[should_fail]
 #[ignore(cfg(windows))]
-fn to_str_radix17() {
+pub fn to_str_radix17() {
     uint::to_str(100u, 17u);
 }
 
 #[test]
-fn test_times() {
+pub fn test_times() {
     use iter::Times;
     let ten = 10 as T;
     let mut accum = 0;