Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Stabilize the std::str module #19741

Merged
merged 2 commits into from
Dec 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub fn parse_config(args: Vec<String> ) -> Config {
matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent")
.and_then(|s| from_str::<f64>(s.as_slice())),
.and_then(|s| s.as_slice().parse::<f64>()),
runtool: matches.opt_str("runtool"),
host_rustcflags: matches.opt_str("host-rustcflags"),
target_rustcflags: matches.opt_str("target-rustcflags"),
Expand Down Expand Up @@ -190,9 +190,7 @@ pub fn log_config(config: &Config) {
logv(c, format!("filter: {}",
opt_str(&config.filter
.as_ref()
.map(|re| {
re.to_string().into_string()
}))));
.map(|re| re.to_string()))));
logv(c, format!("runtool: {}", opt_str(&config.runtool)));
logv(c, format!("host-rustcflags: {}",
opt_str(&config.host_rustcflags)));
Expand Down
6 changes: 3 additions & 3 deletions src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,8 @@ pub fn gdb_version_to_int(version_string: &str) -> int {
panic!("{}", error_string);
}

let major: int = from_str(components[0]).expect(error_string);
let minor: int = from_str(components[1]).expect(error_string);
let major: int = components[0].parse().expect(error_string);
let minor: int = components[1].parse().expect(error_string);

return major * 1000 + minor;
}
Expand All @@ -362,6 +362,6 @@ pub fn lldb_version_to_int(version_string: &str) -> int {
"Encountered LLDB version string with unexpected format: {}",
version_string);
let error_string = error_string.as_slice();
let major: int = from_str(version_string).expect(error_string);
let major: int = version_string.parse().expect(error_string);
return major;
}
2 changes: 1 addition & 1 deletion src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ fn split_maybe_args(argstr: &Option<String>) -> Vec<String> {
s.as_slice()
.split(' ')
.filter_map(|s| {
if s.is_whitespace() {
if s.chars().all(|c| c.is_whitespace()) {
None
} else {
Some(s.to_string())
Expand Down
24 changes: 12 additions & 12 deletions src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2257,10 +2257,10 @@ a function for that:
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice());
let input_num: Option<uint> = input.parse();
```

The `from_str` function takes in a `&str` value and converts it into something.
The `parse` function takes in a `&str` value and converts it into something.
We tell it what kind of something with a type hint. Remember our type hint with
`random()`? It looked like this:

Expand All @@ -2279,8 +2279,8 @@ In this case, we say `x` is a `uint` explicitly, so Rust is able to properly
tell `random()` what to generate. In a similar fashion, both of these work:

```{rust,ignore}
let input_num = from_str::<uint>("5"); // input_num: Option<uint>
let input_num: Option<uint> = from_str("5"); // input_num: Option<uint>
let input_num = "5".parse::<uint>(); // input_num: Option<uint>
let input_num: Option<uint> = "5".parse(); // input_num: Option<uint>
```

Anyway, with us now converting our input to a number, our code looks like this:
Expand All @@ -2301,7 +2301,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice());
let input_num: Option<uint> = input.parse();

println!("You guessed: {}", input_num);

Expand Down Expand Up @@ -2350,7 +2350,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice());
let input_num: Option<uint> = input.parse();

let num = match input_num {
Some(num) => num,
Expand Down Expand Up @@ -2395,7 +2395,7 @@ Uh, what? But we did!

... actually, we didn't. See, when you get a line of input from `stdin()`,
you get all the input. Including the `\n` character from you pressing Enter.
Therefore, `from_str()` sees the string `"5\n"` and says "nope, that's not a
Therefore, `parse()` sees the string `"5\n"` and says "nope, that's not a
number; there's non-number stuff in there!" Luckily for us, `&str`s have an easy
method we can use defined on them: `trim()`. One small modification, and our
code looks like this:
Expand All @@ -2416,7 +2416,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice().trim());
let input_num: Option<uint> = input.trim().parse();

let num = match input_num {
Some(num) => num,
Expand Down Expand Up @@ -2491,7 +2491,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice().trim());
let input_num: Option<uint> = input.trim().parse();

let num = match input_num {
Some(num) => num,
Expand Down Expand Up @@ -2566,7 +2566,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice().trim());
let input_num: Option<uint> = input.trim().parse();

let num = match input_num {
Some(num) => num,
Expand Down Expand Up @@ -2621,7 +2621,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice().trim());
let input_num: Option<uint> = input.trim().parse();

let num = match input_num {
Some(num) => num,
Expand Down Expand Up @@ -2697,7 +2697,7 @@ fn main() {
let input = io::stdin().read_line()
.ok()
.expect("Failed to read line");
let input_num: Option<uint> = from_str(input.as_slice().trim());
let input_num: Option<uint> = input.trim().parse();

let num = match input_num {
Some(num) => num,
Expand Down
2 changes: 1 addition & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3177,7 +3177,7 @@ Some examples of call expressions:
# fn add(x: int, y: int) -> int { 0 }

let x: int = add(1, 2);
let pi: Option<f32> = from_str("3.14");
let pi: Option<f32> = "3.14".parse();
```

### Lambda expressions
Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ mod prelude {
// in core and collections (may differ).
pub use slice::{PartialEqSliceExt, OrdSliceExt};
pub use slice::{AsSlice, SliceExt};
pub use str::{from_str, Str, StrPrelude};
pub use str::{from_str, Str};

// from other crates.
pub use alloc::boxed::Box;
pub use unicode::char::UnicodeChar;

// from collections.
pub use slice::{CloneSliceExt, VectorVector};
pub use str::{IntoMaybeOwned, UnicodeStrPrelude, StrAllocating, StrVector};
pub use str::{IntoMaybeOwned, StrVector};
pub use string::{String, ToString};
pub use vec::Vec;
}
Loading