about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/libcore/core.rc2
-rw-r--r--src/libcore/int-template.rs5
-rw-r--r--src/libcore/uint-template.rs5
3 files changed, 12 insertions, 0 deletions
diff --git a/src/libcore/core.rc b/src/libcore/core.rc
index 5b2378a21cd..6cf9c82a511 100644
--- a/src/libcore/core.rc
+++ b/src/libcore/core.rc
@@ -49,6 +49,7 @@ export extfmt;
 export rt;
 export tuple;
 export to_str, to_bytes;
+export from_str;
 export util;
 export dvec, dvec_iter;
 export dlist, dlist_iter;
@@ -188,6 +189,7 @@ mod option_iter {
 mod result;
 mod to_str;
 mod to_bytes;
+mod from_str;
 mod util;
 
 // Data structure modules
diff --git a/src/libcore/int-template.rs b/src/libcore/int-template.rs
index 757a64d0d79..6c972da7353 100644
--- a/src/libcore/int-template.rs
+++ b/src/libcore/int-template.rs
@@ -4,6 +4,7 @@
 
 import T = inst::T;
 import cmp::{Eq, Ord};
+import from_str::FromStr;
 import num::from_int;
 
 export min_value, max_value;
@@ -162,6 +163,10 @@ fn parse_buf(buf: &[u8], radix: uint) -> Option<T> {
 /// Parse a string to an int
 fn from_str(s: &str) -> Option<T> { parse_buf(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 {
     do to_str_bytes(n, radix) |slice| {
diff --git a/src/libcore/uint-template.rs b/src/libcore/uint-template.rs
index dfab2e36096..cf4abe4e16f 100644
--- a/src/libcore/uint-template.rs
+++ b/src/libcore/uint-template.rs
@@ -4,6 +4,7 @@
 
 import T = inst::T;
 import cmp::{Eq, Ord};
+import from_str::FromStr;
 
 export min_value, max_value;
 export min, max;
@@ -145,6 +146,10 @@ fn parse_buf(buf: &[const u8], radix: uint) -> Option<T> {
 /// Parse a string to an int
 fn from_str(s: &str) -> Option<T> { parse_buf(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> {
     if str::len(buf) == 0u { return None; }