about summary refs log tree commit diff
path: root/src/libcore/uint-template.rs
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-09-03 13:09:24 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-09-03 13:09:24 -0700
commitaefc884cf6e1b2efbb6b629689b1daa3ebbd1e38 (patch)
treebdb52c11011d42758486550e8f0d79bfcbee501e /src/libcore/uint-template.rs
parent07ee2997e6d003d64fe12373faab1e8e9483b0ed (diff)
libcore: Add a from_str trait
Diffstat (limited to 'src/libcore/uint-template.rs')
-rw-r--r--src/libcore/uint-template.rs5
1 files changed, 5 insertions, 0 deletions
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; }