Made from_str pure

This commit is contained in:
Jesse Jones 2012-11-17 11:01:08 -08:00 committed by Brian Anderson
parent 361aea94f2
commit 0fd9c9d054
3 changed files with 13 additions and 7 deletions

View File

@ -7,6 +7,6 @@
use option::Option;
pub trait FromStr {
static fn from_str(s: &str) -> Option<self>;
static pure fn from_str(s: &str) -> Option<self>;
}

View File

@ -106,7 +106,7 @@ impl T: iter::Times {
* * buf - A byte buffer
* * radix - The base of the number
*/
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
pub pure 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;
@ -129,10 +129,13 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
}
/// Parse a string to an int
pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
pub pure 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) }
static pure fn from_str(s: &str) -> Option<T> { from_str(s) }
}
/// Convert to a string in a given base

View File

@ -100,7 +100,7 @@ impl T: iter::Times {
*
* `buf` must not be empty
*/
pub fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
pub pure 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;
@ -117,10 +117,13 @@ pub fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
}
/// Parse a string to an int
pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
pub pure 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) }
static pure fn from_str(s: &str) -> Option<T> { from_str(s) }
}
/// Parse a string as an unsigned integer.