Remove {uint,int,u64,i64,...}::from_str,from_str_radix
Remove these in favor of the two traits themselves and the wrapper function std::from_str::from_str. Add the function std::num::from_str_radix in the corresponding role for the FromStrRadix trait.
This commit is contained in:
parent
4ecb0a372d
commit
8522341274
@ -91,7 +91,7 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
[a, b] => {
|
[a, b] => {
|
||||||
|
|
||||||
// 5. Try parsing both fields as ints.
|
// 5. Try parsing both fields as ints.
|
||||||
match (int::from_str(a), int::from_str(b)) {
|
match (from_str::<int>(a), from_str::<int>(b)) {
|
||||||
|
|
||||||
// 6. If parsing succeeded for both, push both.
|
// 6. If parsing succeeded for both, push both.
|
||||||
(Some(a), Some(b)) => pairs.push((a,b)),
|
(Some(a), Some(b)) => pairs.push((a,b)),
|
||||||
@ -124,7 +124,7 @@ for conveying a value of type `T`, represented as `Some(T)`
|
|||||||
_or_ the sentinel `None`, to indicate the absence of a `T` value.
|
_or_ the sentinel `None`, to indicate the absence of a `T` value.
|
||||||
For simple APIs, it may be sufficient to encode errors as `Option<T>`,
|
For simple APIs, it may be sufficient to encode errors as `Option<T>`,
|
||||||
returning `Some(T)` on success and `None` on error.
|
returning `Some(T)` on success and `None` on error.
|
||||||
In the example program, the call to `int::from_str` returns `Option<int>`
|
In the example program, the call to `from_str::<int>` returns `Option<int>`
|
||||||
with the understanding that "all parse errors" result in `None`.
|
with the understanding that "all parse errors" result in `None`.
|
||||||
The resulting `Option<int>` values are matched against the pattern `(Some(a), Some(b))`
|
The resulting `Option<int>` values are matched against the pattern `(Some(a), Some(b))`
|
||||||
in steps 5 and 6 in the example program,
|
in steps 5 and 6 in the example program,
|
||||||
@ -161,7 +161,7 @@ This second mechanism for indicating an error is called a `Result`.
|
|||||||
The type `std::result::Result<T,E>` is another simple `enum` type with two forms, `Ok(T)` and `Err(E)`.
|
The type `std::result::Result<T,E>` is another simple `enum` type with two forms, `Ok(T)` and `Err(E)`.
|
||||||
The `Result` type is not substantially different from the `Option` type in terms of its ergonomics.
|
The `Result` type is not substantially different from the `Option` type in terms of its ergonomics.
|
||||||
Its main advantage is that the error constructor `Err(E)` can convey _more detail_ about the error.
|
Its main advantage is that the error constructor `Err(E)` can convey _more detail_ about the error.
|
||||||
For example, the `int::from_str` API could be reformed
|
For example, the `from_str` API could be reformed
|
||||||
to return a `Result` carrying an informative description of a parse error,
|
to return a `Result` carrying an informative description of a parse error,
|
||||||
like this:
|
like this:
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ enum IntParseErr {
|
|||||||
BadChar(char)
|
BadChar(char)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn int::from_str(&str) -> Result<int,IntParseErr> {
|
fn from_str(&str) -> Result<int,IntParseErr> {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
~~~~
|
~~~~
|
||||||
@ -297,8 +297,8 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
let line = fi.read_line();
|
let line = fi.read_line();
|
||||||
let fields = line.word_iter().to_owned_vec();
|
let fields = line.word_iter().to_owned_vec();
|
||||||
match fields {
|
match fields {
|
||||||
[a, b] => pairs.push((int::from_str(a).unwrap(),
|
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
|
||||||
int::from_str(b).unwrap())),
|
from_str::<int>(b).unwrap())),
|
||||||
|
|
||||||
// Explicitly fail on malformed lines.
|
// Explicitly fail on malformed lines.
|
||||||
_ => fail!()
|
_ => fail!()
|
||||||
@ -398,8 +398,8 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
let line = fi.read_line();
|
let line = fi.read_line();
|
||||||
let fields = line.word_iter().to_owned_vec();
|
let fields = line.word_iter().to_owned_vec();
|
||||||
match fields {
|
match fields {
|
||||||
[a, b] => pairs.push((int::from_str(a).unwrap(),
|
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
|
||||||
int::from_str(b).unwrap())),
|
from_str::<int>(b).unwrap())),
|
||||||
|
|
||||||
// On malformed lines, call the condition handler and
|
// On malformed lines, call the condition handler and
|
||||||
// push whatever the condition handler returns.
|
// push whatever the condition handler returns.
|
||||||
@ -475,8 +475,8 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
let line = fi.read_line();
|
let line = fi.read_line();
|
||||||
let fields = line.word_iter().to_owned_vec();
|
let fields = line.word_iter().to_owned_vec();
|
||||||
match fields {
|
match fields {
|
||||||
[a, b] => pairs.push((int::from_str(a).unwrap(),
|
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
|
||||||
int::from_str(b).unwrap())),
|
from_str::<int>(b).unwrap())),
|
||||||
_ => pairs.push(malformed_line::cond.raise(line.clone()))
|
_ => pairs.push(malformed_line::cond.raise(line.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -553,8 +553,8 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
let line = fi.read_line();
|
let line = fi.read_line();
|
||||||
let fields = line.word_iter().to_owned_vec();
|
let fields = line.word_iter().to_owned_vec();
|
||||||
match fields {
|
match fields {
|
||||||
[a, b] => pairs.push((int::from_str(a).unwrap(),
|
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
|
||||||
int::from_str(b).unwrap())),
|
from_str::<int>(b).unwrap())),
|
||||||
|
|
||||||
// On malformed lines, call the condition handler and
|
// On malformed lines, call the condition handler and
|
||||||
// either ignore the line (if the handler returns `None`)
|
// either ignore the line (if the handler returns `None`)
|
||||||
@ -649,8 +649,8 @@ fn read_int_pairs() -> ~[(int,int)] {
|
|||||||
let line = fi.read_line();
|
let line = fi.read_line();
|
||||||
let fields = line.word_iter().to_owned_vec();
|
let fields = line.word_iter().to_owned_vec();
|
||||||
match fields {
|
match fields {
|
||||||
[a, b] => pairs.push((int::from_str(a).unwrap(),
|
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
|
||||||
int::from_str(b).unwrap())),
|
from_str::<int>(b).unwrap())),
|
||||||
|
|
||||||
// On malformed lines, call the condition handler and
|
// On malformed lines, call the condition handler and
|
||||||
// take action appropriate to the enum value returned.
|
// take action appropriate to the enum value returned.
|
||||||
@ -776,7 +776,7 @@ fn main() {
|
|||||||
// Parse an int; if parsing fails, call the condition handler and
|
// Parse an int; if parsing fails, call the condition handler and
|
||||||
// return whatever it returns.
|
// return whatever it returns.
|
||||||
fn parse_int(x: &str) -> int {
|
fn parse_int(x: &str) -> int {
|
||||||
match int::from_str(x) {
|
match from_str::<int>(x) {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => malformed_int::cond.raise(x.to_owned())
|
None => malformed_int::cond.raise(x.to_owned())
|
||||||
}
|
}
|
||||||
@ -833,8 +833,8 @@ There are three other things to note in this variant of the example program:
|
|||||||
so long as the `raise` occurs within a callee (of any depth) of the logic protected by the `trap` call,
|
so long as the `raise` occurs within a callee (of any depth) of the logic protected by the `trap` call,
|
||||||
it will invoke the handler.
|
it will invoke the handler.
|
||||||
|
|
||||||
- This variant insulates callers from a design choice in the `int` library:
|
- This variant insulates callers from a design choice in the library:
|
||||||
the `int::from_str` function was designed to return an `Option<int>`,
|
the `from_str` function was designed to return an `Option<int>`,
|
||||||
but this program insulates callers from that choice,
|
but this program insulates callers from that choice,
|
||||||
routing all `None` values that arise from parsing integers in this file into the condition.
|
routing all `None` values that arise from parsing integers in this file into the condition.
|
||||||
|
|
||||||
|
@ -538,8 +538,8 @@ mod test {
|
|||||||
|
|
||||||
do input_vec_state(filenames) |line, state| {
|
do input_vec_state(filenames) |line, state| {
|
||||||
let nums: ~[&str] = line.split_iter(' ').collect();
|
let nums: ~[&str] = line.split_iter(' ').collect();
|
||||||
let file_num = uint::from_str(nums[0]).unwrap();
|
let file_num = from_str::<uint>(nums[0]).unwrap();
|
||||||
let line_num = uint::from_str(nums[1]).unwrap();
|
let line_num = from_str::<uint>(nums[1]).unwrap();
|
||||||
assert_eq!(line_num, state.line_num_file);
|
assert_eq!(line_num, state.line_num_file);
|
||||||
assert_eq!(file_num * 3 + line_num, state.line_num);
|
assert_eq!(file_num * 3 + line_num, state.line_num);
|
||||||
true
|
true
|
||||||
|
@ -19,7 +19,6 @@ use std::io::{ReaderUtil};
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::option::{Option, Some, None};
|
use std::option::{Option, Some, None};
|
||||||
use std::to_str::ToStr;
|
use std::to_str::ToStr;
|
||||||
use std::uint;
|
|
||||||
|
|
||||||
#[deriving(Clone, Eq)]
|
#[deriving(Clone, Eq)]
|
||||||
pub enum Identifier {
|
pub enum Identifier {
|
||||||
@ -140,7 +139,7 @@ fn take_nonempty_prefix(rdr: @io::Reader,
|
|||||||
|
|
||||||
fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
|
fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
|
||||||
let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit);
|
let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit);
|
||||||
match uint::from_str(s) {
|
match from_str::<uint>(s) {
|
||||||
None => { bad_parse::cond.raise(()); (0, ch) },
|
None => { bad_parse::cond.raise(()); (0, ch) },
|
||||||
Some(i) => (i, ch)
|
Some(i) => (i, ch)
|
||||||
}
|
}
|
||||||
@ -149,7 +148,7 @@ fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
|
|||||||
fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
|
fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
|
||||||
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
|
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
|
||||||
if s.iter().all(char::is_digit) {
|
if s.iter().all(char::is_digit) {
|
||||||
match uint::from_str(s) {
|
match from_str::<uint>(s) {
|
||||||
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
|
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
|
||||||
Some(i) => (Numeric(i), ch)
|
Some(i) => (Numeric(i), ch)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,6 @@ use std::task;
|
|||||||
use std::to_str::ToStr;
|
use std::to_str::ToStr;
|
||||||
use std::f64;
|
use std::f64;
|
||||||
use std::os;
|
use std::os;
|
||||||
use std::uint;
|
|
||||||
|
|
||||||
|
|
||||||
// The name of a test. By convention this follows the rules for rust
|
// The name of a test. By convention this follows the rules for rust
|
||||||
@ -253,7 +252,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
|
|||||||
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
|
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
|
||||||
|
|
||||||
let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
|
let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
|
||||||
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| f64::from_str(s).unwrap());
|
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| from_str::<f64>(s).unwrap());
|
||||||
|
|
||||||
let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
|
let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
|
||||||
let save_metrics = save_metrics.map_move(|s| Path(s));
|
let save_metrics = save_metrics.map_move(|s| Path(s));
|
||||||
@ -281,7 +280,7 @@ pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
|
|||||||
None => None,
|
None => None,
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
match s.split_iter('.').to_owned_vec() {
|
match s.split_iter('.').to_owned_vec() {
|
||||||
[a, b] => match (uint::from_str(a), uint::from_str(b)) {
|
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
|
||||||
(Some(a), Some(b)) => Some((a,b)),
|
(Some(a), Some(b)) => Some((a,b)),
|
||||||
_ => None
|
_ => None
|
||||||
},
|
},
|
||||||
|
@ -383,20 +383,6 @@ impl Primitive for $T {
|
|||||||
|
|
||||||
// String conversion functions and impl str -> num
|
// String conversion functions and impl str -> num
|
||||||
|
|
||||||
/// Parse a string as a number in base 10.
|
|
||||||
#[inline]
|
|
||||||
pub fn from_str(s: &str) -> Option<$T> {
|
|
||||||
strconv::from_str_common(s, 10u, true, false, false,
|
|
||||||
strconv::ExpNone, false, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a string as a number in the given base.
|
|
||||||
#[inline]
|
|
||||||
pub fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
|
||||||
strconv::from_str_common(s, radix, true, false, false,
|
|
||||||
strconv::ExpNone, false, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a byte slice as a number in the given base.
|
/// Parse a byte slice as a number in the given base.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
||||||
@ -407,14 +393,16 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
|||||||
impl FromStr for $T {
|
impl FromStr for $T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_str(s: &str) -> Option<$T> {
|
fn from_str(s: &str) -> Option<$T> {
|
||||||
from_str(s)
|
strconv::from_str_common(s, 10u, true, false, false,
|
||||||
|
strconv::ExpNone, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStrRadix for $T {
|
impl FromStrRadix for $T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
||||||
from_str_radix(s, radix)
|
strconv::from_str_common(s, radix, true, false, false,
|
||||||
|
strconv::ExpNone, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,10 +450,7 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use int;
|
use int;
|
||||||
use i16;
|
|
||||||
use i32;
|
use i32;
|
||||||
use i64;
|
|
||||||
use i8;
|
|
||||||
use num;
|
use num;
|
||||||
use sys;
|
use sys;
|
||||||
|
|
||||||
@ -670,20 +655,20 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str() {
|
fn test_from_str() {
|
||||||
assert_eq!(from_str("0"), Some(0 as $T));
|
assert_eq!(from_str::<$T>("0"), Some(0 as $T));
|
||||||
assert_eq!(from_str("3"), Some(3 as $T));
|
assert_eq!(from_str::<$T>("3"), Some(3 as $T));
|
||||||
assert_eq!(from_str("10"), Some(10 as $T));
|
assert_eq!(from_str::<$T>("10"), Some(10 as $T));
|
||||||
assert_eq!(i32::from_str("123456789"), Some(123456789 as i32));
|
assert_eq!(from_str::<i32>("123456789"), Some(123456789 as i32));
|
||||||
assert_eq!(from_str("00100"), Some(100 as $T));
|
assert_eq!(from_str::<$T>("00100"), Some(100 as $T));
|
||||||
|
|
||||||
assert_eq!(from_str("-1"), Some(-1 as $T));
|
assert_eq!(from_str::<$T>("-1"), Some(-1 as $T));
|
||||||
assert_eq!(from_str("-3"), Some(-3 as $T));
|
assert_eq!(from_str::<$T>("-3"), Some(-3 as $T));
|
||||||
assert_eq!(from_str("-10"), Some(-10 as $T));
|
assert_eq!(from_str::<$T>("-10"), Some(-10 as $T));
|
||||||
assert_eq!(i32::from_str("-123456789"), Some(-123456789 as i32));
|
assert_eq!(from_str::<i32>("-123456789"), Some(-123456789 as i32));
|
||||||
assert_eq!(from_str("-00100"), Some(-100 as $T));
|
assert_eq!(from_str::<$T>("-00100"), Some(-100 as $T));
|
||||||
|
|
||||||
assert!(from_str(" ").is_none());
|
assert!(from_str::<$T>(" ").is_none());
|
||||||
assert!(from_str("x").is_none());
|
assert!(from_str::<$T>("x").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -751,36 +736,36 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_int_from_str_overflow() {
|
fn test_int_from_str_overflow() {
|
||||||
let mut i8_val: i8 = 127_i8;
|
let mut i8_val: i8 = 127_i8;
|
||||||
assert_eq!(i8::from_str("127"), Some(i8_val));
|
assert_eq!(from_str::<i8>("127"), Some(i8_val));
|
||||||
assert!(i8::from_str("128").is_none());
|
assert!(from_str::<i8>("128").is_none());
|
||||||
|
|
||||||
i8_val += 1 as i8;
|
i8_val += 1 as i8;
|
||||||
assert_eq!(i8::from_str("-128"), Some(i8_val));
|
assert_eq!(from_str::<i8>("-128"), Some(i8_val));
|
||||||
assert!(i8::from_str("-129").is_none());
|
assert!(from_str::<i8>("-129").is_none());
|
||||||
|
|
||||||
let mut i16_val: i16 = 32_767_i16;
|
let mut i16_val: i16 = 32_767_i16;
|
||||||
assert_eq!(i16::from_str("32767"), Some(i16_val));
|
assert_eq!(from_str::<i16>("32767"), Some(i16_val));
|
||||||
assert!(i16::from_str("32768").is_none());
|
assert!(from_str::<i16>("32768").is_none());
|
||||||
|
|
||||||
i16_val += 1 as i16;
|
i16_val += 1 as i16;
|
||||||
assert_eq!(i16::from_str("-32768"), Some(i16_val));
|
assert_eq!(from_str::<i16>("-32768"), Some(i16_val));
|
||||||
assert!(i16::from_str("-32769").is_none());
|
assert!(from_str::<i16>("-32769").is_none());
|
||||||
|
|
||||||
let mut i32_val: i32 = 2_147_483_647_i32;
|
let mut i32_val: i32 = 2_147_483_647_i32;
|
||||||
assert_eq!(i32::from_str("2147483647"), Some(i32_val));
|
assert_eq!(from_str::<i32>("2147483647"), Some(i32_val));
|
||||||
assert!(i32::from_str("2147483648").is_none());
|
assert!(from_str::<i32>("2147483648").is_none());
|
||||||
|
|
||||||
i32_val += 1 as i32;
|
i32_val += 1 as i32;
|
||||||
assert_eq!(i32::from_str("-2147483648"), Some(i32_val));
|
assert_eq!(from_str::<i32>("-2147483648"), Some(i32_val));
|
||||||
assert!(i32::from_str("-2147483649").is_none());
|
assert!(from_str::<i32>("-2147483649").is_none());
|
||||||
|
|
||||||
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
let mut i64_val: i64 = 9_223_372_036_854_775_807_i64;
|
||||||
assert_eq!(i64::from_str("9223372036854775807"), Some(i64_val));
|
assert_eq!(from_str::<i64>("9223372036854775807"), Some(i64_val));
|
||||||
assert!(i64::from_str("9223372036854775808").is_none());
|
assert!(from_str::<i64>("9223372036854775808").is_none());
|
||||||
|
|
||||||
i64_val += 1 as i64;
|
i64_val += 1 as i64;
|
||||||
assert_eq!(i64::from_str("-9223372036854775808"), Some(i64_val));
|
assert_eq!(from_str::<i64>("-9223372036854775808"), Some(i64_val));
|
||||||
assert!(i64::from_str("-9223372036854775809").is_none());
|
assert!(from_str::<i64>("-9223372036854775809").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -439,6 +439,11 @@ pub trait FromStrRadix {
|
|||||||
fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
fn from_str_radix(str: &str, radix: uint) -> Option<Self>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A utility function that just calls FromStrRadix::from_str_radix
|
||||||
|
pub fn from_str_radix<T: FromStrRadix>(str: &str, radix: uint) -> Option<T> {
|
||||||
|
FromStrRadix::from_str_radix(str, radix)
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculates a power to a given radix, optimized for uint `pow` and `radix`.
|
/// Calculates a power to a given radix, optimized for uint `pow` and `radix`.
|
||||||
///
|
///
|
||||||
/// Returns `radix^pow` as `T`.
|
/// Returns `radix^pow` as `T`.
|
||||||
|
@ -238,20 +238,6 @@ impl Int for $T {}
|
|||||||
|
|
||||||
// String conversion functions and impl str -> num
|
// String conversion functions and impl str -> num
|
||||||
|
|
||||||
/// Parse a string as a number in base 10.
|
|
||||||
#[inline]
|
|
||||||
pub fn from_str(s: &str) -> Option<$T> {
|
|
||||||
strconv::from_str_common(s, 10u, false, false, false,
|
|
||||||
strconv::ExpNone, false, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a string as a number in the given base.
|
|
||||||
#[inline]
|
|
||||||
pub fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
|
||||||
strconv::from_str_common(s, radix, false, false, false,
|
|
||||||
strconv::ExpNone, false, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a byte slice as a number in the given base.
|
/// Parse a byte slice as a number in the given base.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
||||||
@ -262,14 +248,16 @@ pub fn parse_bytes(buf: &[u8], radix: uint) -> Option<$T> {
|
|||||||
impl FromStr for $T {
|
impl FromStr for $T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_str(s: &str) -> Option<$T> {
|
fn from_str(s: &str) -> Option<$T> {
|
||||||
from_str(s)
|
strconv::from_str_common(s, 10u, false, false, false,
|
||||||
|
strconv::ExpNone, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStrRadix for $T {
|
impl FromStrRadix for $T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
fn from_str_radix(s: &str, radix: uint) -> Option<$T> {
|
||||||
from_str_radix(s, radix)
|
strconv::from_str_common(s, radix, false, false, false,
|
||||||
|
strconv::ExpNone, false, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,9 +335,6 @@ mod tests {
|
|||||||
use num;
|
use num;
|
||||||
use sys;
|
use sys;
|
||||||
use u16;
|
use u16;
|
||||||
use u32;
|
|
||||||
use u64;
|
|
||||||
use u8;
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_num() {
|
fn test_num() {
|
||||||
@ -459,15 +444,15 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
pub fn test_from_str() {
|
pub fn test_from_str() {
|
||||||
assert_eq!(from_str("0"), Some(0u as $T));
|
assert_eq!(from_str::<$T>("0"), Some(0u as $T));
|
||||||
assert_eq!(from_str("3"), Some(3u as $T));
|
assert_eq!(from_str::<$T>("3"), Some(3u as $T));
|
||||||
assert_eq!(from_str("10"), Some(10u as $T));
|
assert_eq!(from_str::<$T>("10"), Some(10u as $T));
|
||||||
assert_eq!(u32::from_str("123456789"), Some(123456789 as u32));
|
assert_eq!(from_str::<u32>("123456789"), Some(123456789 as u32));
|
||||||
assert_eq!(from_str("00100"), Some(100u as $T));
|
assert_eq!(from_str::<$T>("00100"), Some(100u as $T));
|
||||||
|
|
||||||
assert!(from_str("").is_none());
|
assert!(from_str::<$T>("").is_none());
|
||||||
assert!(from_str(" ").is_none());
|
assert!(from_str::<$T>(" ").is_none());
|
||||||
assert!(from_str("x").is_none());
|
assert!(from_str::<$T>("x").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -514,36 +499,36 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_uint_from_str_overflow() {
|
fn test_uint_from_str_overflow() {
|
||||||
let mut u8_val: u8 = 255_u8;
|
let mut u8_val: u8 = 255_u8;
|
||||||
assert_eq!(u8::from_str("255"), Some(u8_val));
|
assert_eq!(from_str::<u8>("255"), Some(u8_val));
|
||||||
assert!(u8::from_str("256").is_none());
|
assert!(from_str::<u8>("256").is_none());
|
||||||
|
|
||||||
u8_val += 1 as u8;
|
u8_val += 1 as u8;
|
||||||
assert_eq!(u8::from_str("0"), Some(u8_val));
|
assert_eq!(from_str::<u8>("0"), Some(u8_val));
|
||||||
assert!(u8::from_str("-1").is_none());
|
assert!(from_str::<u8>("-1").is_none());
|
||||||
|
|
||||||
let mut u16_val: u16 = 65_535_u16;
|
let mut u16_val: u16 = 65_535_u16;
|
||||||
assert_eq!(u16::from_str("65535"), Some(u16_val));
|
assert_eq!(from_str::<u16>("65535"), Some(u16_val));
|
||||||
assert!(u16::from_str("65536").is_none());
|
assert!(from_str::<u16>("65536").is_none());
|
||||||
|
|
||||||
u16_val += 1 as u16;
|
u16_val += 1 as u16;
|
||||||
assert_eq!(u16::from_str("0"), Some(u16_val));
|
assert_eq!(from_str::<u16>("0"), Some(u16_val));
|
||||||
assert!(u16::from_str("-1").is_none());
|
assert!(from_str::<u16>("-1").is_none());
|
||||||
|
|
||||||
let mut u32_val: u32 = 4_294_967_295_u32;
|
let mut u32_val: u32 = 4_294_967_295_u32;
|
||||||
assert_eq!(u32::from_str("4294967295"), Some(u32_val));
|
assert_eq!(from_str::<u32>("4294967295"), Some(u32_val));
|
||||||
assert!(u32::from_str("4294967296").is_none());
|
assert!(from_str::<u32>("4294967296").is_none());
|
||||||
|
|
||||||
u32_val += 1 as u32;
|
u32_val += 1 as u32;
|
||||||
assert_eq!(u32::from_str("0"), Some(u32_val));
|
assert_eq!(from_str::<u32>("0"), Some(u32_val));
|
||||||
assert!(u32::from_str("-1").is_none());
|
assert!(from_str::<u32>("-1").is_none());
|
||||||
|
|
||||||
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
let mut u64_val: u64 = 18_446_744_073_709_551_615_u64;
|
||||||
assert_eq!(u64::from_str("18446744073709551615"), Some(u64_val));
|
assert_eq!(from_str::<u64>("18446744073709551615"), Some(u64_val));
|
||||||
assert!(u64::from_str("18446744073709551616").is_none());
|
assert!(from_str::<u64>("18446744073709551616").is_none());
|
||||||
|
|
||||||
u64_val += 1 as u64;
|
u64_val += 1 as u64;
|
||||||
assert_eq!(u64::from_str("0"), Some(u64_val));
|
assert_eq!(from_str::<u64>("0"), Some(u64_val));
|
||||||
assert!(u64::from_str("-1").is_none());
|
assert!(from_str::<u64>("-1").is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
use from_str::from_str;
|
||||||
use libc::{uintptr_t, exit, STDERR_FILENO};
|
use libc::{uintptr_t, exit, STDERR_FILENO};
|
||||||
use option::{Some, None, Option};
|
use option::{Some, None, Option};
|
||||||
use rt::util::dumb_println;
|
use rt::util::dumb_println;
|
||||||
@ -28,7 +29,7 @@ static log_level_names : &'static[&'static str] = &'static["error", "warn", "inf
|
|||||||
|
|
||||||
/// Parse an individual log level that is either a number or a symbolic log level
|
/// Parse an individual log level that is either a number or a symbolic log level
|
||||||
fn parse_log_level(level: &str) -> Option<u32> {
|
fn parse_log_level(level: &str) -> Option<u32> {
|
||||||
let num = u32::from_str(level);
|
let num = from_str::<u32>(level);
|
||||||
let mut log_level;
|
let mut log_level;
|
||||||
match num {
|
match num {
|
||||||
Some(num) => {
|
Some(num) => {
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use libc;
|
use libc;
|
||||||
use uint;
|
|
||||||
use option::{Some, None};
|
use option::{Some, None};
|
||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
@ -382,9 +381,10 @@ fn base_port() -> uint {
|
|||||||
/// stress tests. Default 1.
|
/// stress tests. Default 1.
|
||||||
pub fn stress_factor() -> uint {
|
pub fn stress_factor() -> uint {
|
||||||
use os::getenv;
|
use os::getenv;
|
||||||
|
use from_str::from_str;
|
||||||
|
|
||||||
match getenv("RUST_RT_STRESS") {
|
match getenv("RUST_RT_STRESS") {
|
||||||
Some(val) => uint::from_str(val).unwrap(),
|
Some(val) => from_str::<uint>(val).unwrap(),
|
||||||
None => 1
|
None => 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ use parse::token::{str_to_ident};
|
|||||||
use std::cast::transmute;
|
use std::cast::transmute;
|
||||||
use std::char;
|
use std::char;
|
||||||
use std::either;
|
use std::either;
|
||||||
use std::u64;
|
use std::num::from_str_radix;
|
||||||
use std::util;
|
use std::util;
|
||||||
|
|
||||||
pub use ext::tt::transcribe::{TtReader, new_tt_reader};
|
pub use ext::tt::transcribe::{TtReader, new_tt_reader};
|
||||||
@ -444,7 +444,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
|||||||
if num_str.len() == 0u {
|
if num_str.len() == 0u {
|
||||||
rdr.fatal(~"no valid digits found for number");
|
rdr.fatal(~"no valid digits found for number");
|
||||||
}
|
}
|
||||||
let parsed = match u64::from_str_radix(num_str, base as uint) {
|
let parsed = match from_str_radix::<u64>(num_str, base as uint) {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => rdr.fatal(~"int literal is too large")
|
None => rdr.fatal(~"int literal is too large")
|
||||||
};
|
};
|
||||||
@ -509,7 +509,7 @@ fn scan_number(c: char, rdr: @mut StringReader) -> token::Token {
|
|||||||
if num_str.len() == 0u {
|
if num_str.len() == 0u {
|
||||||
rdr.fatal(~"no valid digits found for number");
|
rdr.fatal(~"no valid digits found for number");
|
||||||
}
|
}
|
||||||
let parsed = match u64::from_str_radix(num_str, base as uint) {
|
let parsed = match from_str_radix::<u64>(num_str, base as uint) {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => rdr.fatal(~"int literal is too large")
|
None => rdr.fatal(~"int literal is too large")
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ pub trait read {
|
|||||||
|
|
||||||
impl read for int {
|
impl read for int {
|
||||||
fn readMaybe(s: ~str) -> Option<int> {
|
fn readMaybe(s: ~str) -> Option<int> {
|
||||||
int::from_str(s)
|
from_str::<int>(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ fn main() {
|
|||||||
let args = os::args();
|
let args = os::args();
|
||||||
let n_keys = {
|
let n_keys = {
|
||||||
if args.len() == 2 {
|
if args.len() == 2 {
|
||||||
uint::from_str(args[1]).unwrap()
|
from_str::<uint>(args[1]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
1000000
|
1000000
|
||||||
}
|
}
|
||||||
|
@ -157,7 +157,7 @@ fn main() {
|
|||||||
let args = os::args();
|
let args = os::args();
|
||||||
let num_keys = {
|
let num_keys = {
|
||||||
if args.len() == 2 {
|
if args.len() == 2 {
|
||||||
uint::from_str(args[1]).unwrap()
|
from_str::<uint>(args[1]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
100 // woefully inadequate for any real measurement
|
100 // woefully inadequate for any real measurement
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ fn main() {
|
|||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let n = uint::from_str(args[1]).unwrap();
|
let n = from_str::<uint>(args[1]).unwrap();
|
||||||
|
|
||||||
for i in range(0u, n) {
|
for i in range(0u, n) {
|
||||||
let x = i.to_str();
|
let x = i.to_str();
|
||||||
|
@ -418,8 +418,8 @@ fn main() {
|
|||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let scale = uint::from_str(args[1]).unwrap();
|
let scale = from_str::<uint>(args[1]).unwrap();
|
||||||
let num_keys = uint::from_str(args[2]).unwrap();
|
let num_keys = from_str::<uint>(args[2]).unwrap();
|
||||||
let do_validate = false;
|
let do_validate = false;
|
||||||
let do_sequential = true;
|
let do_sequential = true;
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ fn run(args: &[~str]) {
|
|||||||
|
|
||||||
let to_child = SharedChan::new(to_child);
|
let to_child = SharedChan::new(to_child);
|
||||||
|
|
||||||
let size = uint::from_str(args[1]).unwrap();
|
let size = from_str::<uint>(args[1]).unwrap();
|
||||||
let workers = uint::from_str(args[2]).unwrap();
|
let workers = from_str::<uint>(args[2]).unwrap();
|
||||||
let num_bytes = 100;
|
let num_bytes = 100;
|
||||||
let start = extra::time::precise_time_s();
|
let start = extra::time::precise_time_s();
|
||||||
let mut worker_results = ~[];
|
let mut worker_results = ~[];
|
||||||
|
@ -53,8 +53,8 @@ fn run(args: &[~str]) {
|
|||||||
let (from_parent, to_child) = stream();
|
let (from_parent, to_child) = stream();
|
||||||
let to_child = SharedChan::new(to_child);
|
let to_child = SharedChan::new(to_child);
|
||||||
|
|
||||||
let size = uint::from_str(args[1]).unwrap();
|
let size = from_str::<uint>(args[1]).unwrap();
|
||||||
let workers = uint::from_str(args[2]).unwrap();
|
let workers = from_str::<uint>(args[2]).unwrap();
|
||||||
let num_bytes = 100;
|
let num_bytes = 100;
|
||||||
let start = extra::time::precise_time_s();
|
let start = extra::time::precise_time_s();
|
||||||
let mut worker_results = ~[];
|
let mut worker_results = ~[];
|
||||||
|
@ -78,8 +78,8 @@ fn main() {
|
|||||||
args.clone()
|
args.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let num_tasks = uint::from_str(args[1]).unwrap();
|
let num_tasks = from_str::<uint>(args[1]).unwrap();
|
||||||
let msg_per_task = uint::from_str(args[2]).unwrap();
|
let msg_per_task = from_str::<uint>(args[2]).unwrap();
|
||||||
|
|
||||||
let (num_chan, num_port) = init();
|
let (num_chan, num_port) = init();
|
||||||
let num_chan = Cell::new(num_chan);
|
let num_chan = Cell::new(num_chan);
|
||||||
|
@ -74,8 +74,8 @@ fn main() {
|
|||||||
args.clone()
|
args.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let num_tasks = uint::from_str(args[1]).unwrap();
|
let num_tasks = from_str::<uint>(args[1]).unwrap();
|
||||||
let msg_per_task = uint::from_str(args[2]).unwrap();
|
let msg_per_task = from_str::<uint>(args[2]).unwrap();
|
||||||
|
|
||||||
let (num_chan, num_port) = init();
|
let (num_chan, num_port) = init();
|
||||||
let num_chan = Cell::new(num_chan);
|
let num_chan = Cell::new(num_chan);
|
||||||
|
@ -65,13 +65,13 @@ fn main() {
|
|||||||
|
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
let n = if args.len() == 3 {
|
let n = if args.len() == 3 {
|
||||||
uint::from_str(args[1]).unwrap()
|
from_str::<uint>(args[1]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
10000
|
10000
|
||||||
};
|
};
|
||||||
|
|
||||||
let m = if args.len() == 3 {
|
let m = if args.len() == 3 {
|
||||||
uint::from_str(args[2]).unwrap()
|
from_str::<uint>(args[2]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
4
|
4
|
||||||
};
|
};
|
||||||
|
@ -38,7 +38,7 @@ fn main() {
|
|||||||
|
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
let n = if args.len() == 2 {
|
let n = if args.len() == 2 {
|
||||||
uint::from_str(args[1]).unwrap()
|
from_str::<uint>(args[1]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
10
|
10
|
||||||
};
|
};
|
||||||
|
@ -21,7 +21,7 @@ fn main() {
|
|||||||
|
|
||||||
let args = os::args();
|
let args = os::args();
|
||||||
let n = if args.len() == 2 {
|
let n = if args.len() == 2 {
|
||||||
uint::from_str(args[1]).unwrap()
|
from_str::<uint>(args[1]).unwrap()
|
||||||
} else {
|
} else {
|
||||||
100000
|
100000
|
||||||
};
|
};
|
||||||
|
@ -34,6 +34,6 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
let n = int::from_str(args[1]).unwrap();
|
let n = from_str::<int>(args[1]).unwrap();
|
||||||
printfln!("Ack(3,%d): %d\n", n, ack(3, n));
|
printfln!("Ack(3,%d): %d\n", n, ack(3, n));
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ fn main() {
|
|||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let n = int::from_str(args[1]).unwrap();
|
let n = from_str::<int>(args[1]).unwrap();
|
||||||
let min_depth = 4;
|
let min_depth = 4;
|
||||||
let mut max_depth;
|
let mut max_depth;
|
||||||
if min_depth + 2 > n {
|
if min_depth + 2 > n {
|
||||||
|
@ -212,7 +212,7 @@ fn main() {
|
|||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let nn = uint::from_str(args[1]).unwrap();
|
let nn = from_str::<uint>(args[1]).unwrap();
|
||||||
|
|
||||||
print_complements();
|
print_complements();
|
||||||
io::println("");
|
io::println("");
|
||||||
|
@ -128,7 +128,7 @@ fn main() {
|
|||||||
io::stdout()
|
io::stdout()
|
||||||
};
|
};
|
||||||
|
|
||||||
let n = int::from_str(args[1]).unwrap();
|
let n = from_str::<int>(args[1]).unwrap();
|
||||||
|
|
||||||
let iub: ~[AminoAcids] =
|
let iub: ~[AminoAcids] =
|
||||||
make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
|
make_cumulative(~[acid('a', 27u32), acid('c', 12u32), acid('g', 12u32),
|
||||||
|
@ -30,6 +30,6 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
let n = int::from_str(args[1]).unwrap();
|
let n = from_str::<int>(args[1]).unwrap();
|
||||||
printfln!("%d\n", fib(n));
|
printfln!("%d\n", fib(n));
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,8 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
let max = uint::from_str(args[1]).unwrap();
|
let max = from_str::<uint>(args[1]).unwrap();
|
||||||
let rep = uint::from_str(args[2]).unwrap();
|
let rep = from_str::<uint>(args[2]).unwrap();
|
||||||
|
|
||||||
let mut checkf = 0.0;
|
let mut checkf = 0.0;
|
||||||
let mut appendf = 0.0;
|
let mut appendf = 0.0;
|
||||||
|
@ -74,9 +74,9 @@ impl Sudoku {
|
|||||||
let comps: ~[&str] = line.trim().split_iter(',').collect();
|
let comps: ~[&str] = line.trim().split_iter(',').collect();
|
||||||
|
|
||||||
if comps.len() == 3u {
|
if comps.len() == 3u {
|
||||||
let row = uint::from_str(comps[0]).unwrap() as u8;
|
let row = from_str::<uint>(comps[0]).unwrap() as u8;
|
||||||
let col = uint::from_str(comps[1]).unwrap() as u8;
|
let col = from_str::<uint>(comps[1]).unwrap() as u8;
|
||||||
g[row][col] = uint::from_str(comps[2]).unwrap() as u8;
|
g[row][col] = from_str::<uint>(comps[2]).unwrap() as u8;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fail!("Invalid sudoku file");
|
fail!("Invalid sudoku file");
|
||||||
|
@ -52,7 +52,7 @@ fn main() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (p,c) = comm::stream();
|
let (p,c) = comm::stream();
|
||||||
child_generation(uint::from_str(args[1]).unwrap(), c);
|
child_generation(from_str::<uint>(args[1]).unwrap(), c);
|
||||||
if p.try_recv().is_none() {
|
if p.try_recv().is_none() {
|
||||||
fail!("it happened when we slumbered");
|
fail!("it happened when we slumbered");
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ fn main() {
|
|||||||
args.clone()
|
args.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
let num_tasks = uint::from_str(args[1]).unwrap();
|
let num_tasks = from_str::<uint>(args[1]).unwrap();
|
||||||
|
|
||||||
// Main group #0 waits for unsupervised group #1.
|
// Main group #0 waits for unsupervised group #1.
|
||||||
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
|
// Grandparent group #1 waits for middle group #2, then fails, killing #3.
|
||||||
|
@ -56,7 +56,7 @@ fn main() {
|
|||||||
args
|
args
|
||||||
};
|
};
|
||||||
|
|
||||||
let children = uint::from_str(args[1]).get();
|
let children = from_str::<uint>(args[1]).get();
|
||||||
let (wait_port, wait_chan) = stream();
|
let (wait_port, wait_chan) = stream();
|
||||||
do task::spawn {
|
do task::spawn {
|
||||||
calc(children, &wait_chan);
|
calc(children, &wait_chan);
|
||||||
|
@ -31,7 +31,7 @@ fn main() {
|
|||||||
} else {
|
} else {
|
||||||
args
|
args
|
||||||
};
|
};
|
||||||
let n = uint::from_str(args[1]).unwrap();
|
let n = from_str::<uint>(args[1]).unwrap();
|
||||||
let mut i = 0u;
|
let mut i = 0u;
|
||||||
while i < n { task::spawn(|| f(n) ); i += 1u; }
|
while i < n { task::spawn(|| f(n) ); i += 1u; }
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ priv fn chop(s: ~str) -> ~str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
priv fn parse_bulk(io: @io::Reader) -> Result {
|
priv fn parse_bulk(io: @io::Reader) -> Result {
|
||||||
match int::from_str(chop(io.read_line())) {
|
match from_str::<int>(chop(io.read_line())) {
|
||||||
None => fail!(),
|
None => fail!(),
|
||||||
Some(-1) => Nil,
|
Some(-1) => Nil,
|
||||||
Some(len) if len >= 0 => parse_data(len as uint, io),
|
Some(len) if len >= 0 => parse_data(len as uint, io),
|
||||||
@ -71,7 +71,7 @@ priv fn parse_bulk(io: @io::Reader) -> Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
priv fn parse_multi(io: @io::Reader) -> Result {
|
priv fn parse_multi(io: @io::Reader) -> Result {
|
||||||
match int::from_str(chop(io.read_line())) {
|
match from_str::<int>(chop(io.read_line())) {
|
||||||
None => fail!(),
|
None => fail!(),
|
||||||
Some(-1) => Nil,
|
Some(-1) => Nil,
|
||||||
Some(0) => List(~[]),
|
Some(0) => List(~[]),
|
||||||
@ -81,7 +81,7 @@ priv fn parse_multi(io: @io::Reader) -> Result {
|
|||||||
}
|
}
|
||||||
|
|
||||||
priv fn parse_int(io: @io::Reader) -> Result {
|
priv fn parse_int(io: @io::Reader) -> Result {
|
||||||
match int::from_str(chop(io.read_line())) {
|
match from_str::<int>(chop(io.read_line())) {
|
||||||
None => fail!(),
|
None => fail!(),
|
||||||
Some(i) => Int(i)
|
Some(i) => Int(i)
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ pub fn main() {
|
|||||||
// sometimes we have had trouble finding
|
// sometimes we have had trouble finding
|
||||||
// the right type for f, as we unified
|
// the right type for f, as we unified
|
||||||
// bot and u32 here
|
// bot and u32 here
|
||||||
let f = match uint::from_str("1234") {
|
let f = match from_str::<uint>("1234") {
|
||||||
None => return (),
|
None => return (),
|
||||||
Some(num) => num as u32
|
Some(num) => num as u32
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user