Skip to content

Commit 0fd9c9d

Browse files
jesse99brson
authored andcommitted
Made from_str pure
1 parent 361aea9 commit 0fd9c9d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/libcore/from_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use option::Option;
88

99
pub trait FromStr {
10-
static fn from_str(s: &str) -> Option<self>;
10+
static pure fn from_str(s: &str) -> Option<self>;
1111
}
1212

src/libcore/int-template.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl T: iter::Times {
106106
* * buf - A byte buffer
107107
* * radix - The base of the number
108108
*/
109-
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
109+
pub pure fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
110110
if vec::len(buf) == 0u { return None; }
111111
let mut i = vec::len(buf) - 1u;
112112
let mut start = 0u;
@@ -129,10 +129,13 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<T> {
129129
}
130130

131131
/// Parse a string to an int
132-
pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
132+
pub pure fn from_str(s: &str) -> Option<T>
133+
{
134+
parse_bytes(str::to_bytes(s), 10u)
135+
}
133136

134137
impl T : FromStr {
135-
static fn from_str(s: &str) -> Option<T> { from_str(s) }
138+
static pure fn from_str(s: &str) -> Option<T> { from_str(s) }
136139
}
137140

138141
/// Convert to a string in a given base

src/libcore/uint-template.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl T: iter::Times {
100100
*
101101
* `buf` must not be empty
102102
*/
103-
pub fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
103+
pub pure fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
104104
if vec::len(buf) == 0u { return None; }
105105
let mut i = vec::len(buf) - 1u;
106106
let mut power = 1u as T;
@@ -117,10 +117,13 @@ pub fn parse_bytes(buf: &[const u8], radix: uint) -> Option<T> {
117117
}
118118

119119
/// Parse a string to an int
120-
pub fn from_str(s: &str) -> Option<T> { parse_bytes(str::to_bytes(s), 10u) }
120+
pub pure fn from_str(s: &str) -> Option<T>
121+
{
122+
parse_bytes(str::to_bytes(s), 10u)
123+
}
121124

122125
impl T : FromStr {
123-
static fn from_str(s: &str) -> Option<T> { from_str(s) }
126+
static pure fn from_str(s: &str) -> Option<T> { from_str(s) }
124127
}
125128

126129
/// Parse a string as an unsigned integer.

0 commit comments

Comments
 (0)