Skip to content

Commit 066c9f5

Browse files
committed
---
yaml --- r: 80823 b: refs/heads/try c: 1e745f1 h: refs/heads/master i: 80821: cba46c3 80819: 581d960 80815: 3d1d306 v: v3
1 parent 8ba06ae commit 066c9f5

39 files changed

+222
-182
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 4c6bf4872012c010f84dc7fa2cdfe87522533f89
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: cbd1eefbd350797b783df119fed7956d7e1c74ad
5-
refs/heads/try: c8c3c3bdd641411134c53117f4c0a449195d1e10
5+
refs/heads/try: 1e745f16790f22fc10652a6ffae36bf5572255bb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/doc/tutorial-conditions.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ fn read_int_pairs() -> ~[(int,int)] {
9191
[a, b] => {
9292
9393
// 5. Try parsing both fields as ints.
94-
match (from_str::<int>(a), from_str::<int>(b)) {
94+
match (int::from_str(a), int::from_str(b)) {
9595
9696
// 6. If parsing succeeded for both, push both.
9797
(Some(a), Some(b)) => pairs.push((a,b)),
@@ -124,7 +124,7 @@ for conveying a value of type `T`, represented as `Some(T)`
124124
_or_ the sentinel `None`, to indicate the absence of a `T` value.
125125
For simple APIs, it may be sufficient to encode errors as `Option<T>`,
126126
returning `Some(T)` on success and `None` on error.
127-
In the example program, the call to `from_str::<int>` returns `Option<int>`
127+
In the example program, the call to `int::from_str` returns `Option<int>`
128128
with the understanding that "all parse errors" result in `None`.
129129
The resulting `Option<int>` values are matched against the pattern `(Some(a), Some(b))`
130130
in steps 5 and 6 in the example program,
@@ -161,7 +161,7 @@ This second mechanism for indicating an error is called a `Result`.
161161
The type `std::result::Result<T,E>` is another simple `enum` type with two forms, `Ok(T)` and `Err(E)`.
162162
The `Result` type is not substantially different from the `Option` type in terms of its ergonomics.
163163
Its main advantage is that the error constructor `Err(E)` can convey _more detail_ about the error.
164-
For example, the `from_str` API could be reformed
164+
For example, the `int::from_str` API could be reformed
165165
to return a `Result` carrying an informative description of a parse error,
166166
like this:
167167

@@ -172,7 +172,7 @@ enum IntParseErr {
172172
BadChar(char)
173173
}
174174
175-
fn from_str(&str) -> Result<int,IntParseErr> {
175+
fn int::from_str(&str) -> Result<int,IntParseErr> {
176176
// ...
177177
}
178178
~~~~
@@ -297,8 +297,8 @@ fn read_int_pairs() -> ~[(int,int)] {
297297
let line = fi.read_line();
298298
let fields = line.word_iter().to_owned_vec();
299299
match fields {
300-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
301-
from_str::<int>(b).unwrap())),
300+
[a, b] => pairs.push((int::from_str(a).unwrap(),
301+
int::from_str(b).unwrap())),
302302
303303
// Explicitly fail on malformed lines.
304304
_ => fail!()
@@ -398,8 +398,8 @@ fn read_int_pairs() -> ~[(int,int)] {
398398
let line = fi.read_line();
399399
let fields = line.word_iter().to_owned_vec();
400400
match fields {
401-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
402-
from_str::<int>(b).unwrap())),
401+
[a, b] => pairs.push((int::from_str(a).unwrap(),
402+
int::from_str(b).unwrap())),
403403
404404
// On malformed lines, call the condition handler and
405405
// push whatever the condition handler returns.
@@ -475,8 +475,8 @@ fn read_int_pairs() -> ~[(int,int)] {
475475
let line = fi.read_line();
476476
let fields = line.word_iter().to_owned_vec();
477477
match fields {
478-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
479-
from_str::<int>(b).unwrap())),
478+
[a, b] => pairs.push((int::from_str(a).unwrap(),
479+
int::from_str(b).unwrap())),
480480
_ => pairs.push(malformed_line::cond.raise(line.clone()))
481481
}
482482
}
@@ -553,8 +553,8 @@ fn read_int_pairs() -> ~[(int,int)] {
553553
let line = fi.read_line();
554554
let fields = line.word_iter().to_owned_vec();
555555
match fields {
556-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
557-
from_str::<int>(b).unwrap())),
556+
[a, b] => pairs.push((int::from_str(a).unwrap(),
557+
int::from_str(b).unwrap())),
558558
559559
// On malformed lines, call the condition handler and
560560
// either ignore the line (if the handler returns `None`)
@@ -649,8 +649,8 @@ fn read_int_pairs() -> ~[(int,int)] {
649649
let line = fi.read_line();
650650
let fields = line.word_iter().to_owned_vec();
651651
match fields {
652-
[a, b] => pairs.push((from_str::<int>(a).unwrap(),
653-
from_str::<int>(b).unwrap())),
652+
[a, b] => pairs.push((int::from_str(a).unwrap(),
653+
int::from_str(b).unwrap())),
654654
655655
// On malformed lines, call the condition handler and
656656
// take action appropriate to the enum value returned.
@@ -776,7 +776,7 @@ fn main() {
776776
// Parse an int; if parsing fails, call the condition handler and
777777
// return whatever it returns.
778778
fn parse_int(x: &str) -> int {
779-
match from_str::<int>(x) {
779+
match int::from_str(x) {
780780
Some(v) => v,
781781
None => malformed_int::cond.raise(x.to_owned())
782782
}
@@ -833,8 +833,8 @@ There are three other things to note in this variant of the example program:
833833
so long as the `raise` occurs within a callee (of any depth) of the logic protected by the `trap` call,
834834
it will invoke the handler.
835835

836-
- This variant insulates callers from a design choice in the library:
837-
the `from_str` function was designed to return an `Option<int>`,
836+
- This variant insulates callers from a design choice in the `int` library:
837+
the `int::from_str` function was designed to return an `Option<int>`,
838838
but this program insulates callers from that choice,
839839
routing all `None` values that arise from parsing integers in this file into the condition.
840840

@@ -873,4 +873,4 @@ To compensate for this risk, correct C++ and Java code must program in an extrem
873873
or else risk introducing silent and very difficult-to-debug errors due to control resuming in a corrupted heap after a caught exception.
874874
These errors are frequently memory-safety errors, which Rust strives to eliminate,
875875
and so Rust unwinding is unrecoverable within a single task:
876-
once unwinding starts, the entire local heap of a task is destroyed and the task is terminated.
876+
once unwinding starts, the entire local heap of a task is destroyed and the task is terminated.

branches/try/src/libextra/fileinput.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ mod test {
538538

539539
do input_vec_state(filenames) |line, state| {
540540
let nums: ~[&str] = line.split_iter(' ').collect();
541-
let file_num = from_str::<uint>(nums[0]).unwrap();
542-
let line_num = from_str::<uint>(nums[1]).unwrap();
541+
let file_num = uint::from_str(nums[0]).unwrap();
542+
let line_num = uint::from_str(nums[1]).unwrap();
543543
assert_eq!(line_num, state.line_num_file);
544544
assert_eq!(file_num * 3 + line_num, state.line_num);
545545
true

branches/try/src/libextra/semver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::io::{ReaderUtil};
1919
use std::io;
2020
use std::option::{Option, Some, None};
2121
use std::to_str::ToStr;
22+
use std::uint;
2223

2324
#[deriving(Clone, Eq)]
2425
pub enum Identifier {
@@ -139,7 +140,7 @@ fn take_nonempty_prefix(rdr: @io::Reader,
139140

140141
fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
141142
let (s, ch) = take_nonempty_prefix(rdr, ch, char::is_digit);
142-
match from_str::<uint>(s) {
143+
match uint::from_str(s) {
143144
None => { bad_parse::cond.raise(()); (0, ch) },
144145
Some(i) => (i, ch)
145146
}
@@ -148,7 +149,7 @@ fn take_num(rdr: @io::Reader, ch: char) -> (uint, char) {
148149
fn take_ident(rdr: @io::Reader, ch: char) -> (Identifier, char) {
149150
let (s,ch) = take_nonempty_prefix(rdr, ch, char::is_alphanumeric);
150151
if s.iter().all(char::is_digit) {
151-
match from_str::<uint>(s) {
152+
match uint::from_str(s) {
152153
None => { bad_parse::cond.raise(()); (Numeric(0), ch) },
153154
Some(i) => (Numeric(i), ch)
154155
}

branches/try/src/libextra/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use std::task;
3737
use std::to_str::ToStr;
3838
use std::f64;
3939
use std::os;
40+
use std::uint;
4041

4142

4243
// The name of a test. By convention this follows the rules for rust
@@ -252,7 +253,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
252253
let ratchet_metrics = ratchet_metrics.map_move(|s| Path(s));
253254

254255
let ratchet_noise_percent = getopts::opt_maybe_str(&matches, "ratchet-noise-percent");
255-
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| from_str::<f64>(s).unwrap());
256+
let ratchet_noise_percent = ratchet_noise_percent.map_move(|s| f64::from_str(s).unwrap());
256257

257258
let save_metrics = getopts::opt_maybe_str(&matches, "save-metrics");
258259
let save_metrics = save_metrics.map_move(|s| Path(s));
@@ -280,7 +281,7 @@ pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
280281
None => None,
281282
Some(s) => {
282283
match s.split_iter('.').to_owned_vec() {
283-
[a, b] => match (from_str::<uint>(a), from_str::<uint>(b)) {
284+
[a, b] => match (uint::from_str(a), uint::from_str(b)) {
284285
(Some(a), Some(b)) => Some((a,b)),
285286
_ => None
286287
},

0 commit comments

Comments
 (0)