diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-22 09:04:23 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-01-02 08:54:06 -0800 |
| commit | 56290a004493a5d2e211f056601533253497df60 (patch) | |
| tree | ab0e7c227f9ba155ea5bfd0390cada43062924c1 /src/doc | |
| parent | 71b46b18a274edc7f7fb60b490e5ebbb9c911462 (diff) | |
std: Stabilize the prelude module
This commit is an implementation of [RFC 503][rfc] which is a stabilization story for the prelude. Most of the RFC was directly applied, removing reexports. Some reexports are kept around, however: * `range` remains until range syntax has landed to reduce churn. * `Path` and `GenericPath` remain until path reform lands. This is done to prevent many imports of `GenericPath` which will soon be removed. * All `io` traits remain until I/O reform lands so imports can be rewritten all at once to `std::io::prelude::*`. This is a breaking change because many prelude reexports have been removed, and the RFC can be consulted for the exact list of removed reexports, as well as to find the locations of where to import them. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0503-prelude-stabilization.md [breaking-change] Closes #20068
Diffstat (limited to 'src/doc')
| -rw-r--r-- | src/doc/guide-ffi.md | 2 | ||||
| -rw-r--r-- | src/doc/guide.md | 173 | ||||
| -rw-r--r-- | src/doc/reference.md | 4 |
3 files changed, 97 insertions, 82 deletions
diff --git a/src/doc/guide-ffi.md b/src/doc/guide-ffi.md index 3a87271ede7..b8808eaf57d 100644 --- a/src/doc/guide-ffi.md +++ b/src/doc/guide-ffi.md @@ -450,6 +450,8 @@ them. ~~~no_run extern crate libc; + +use std::c_str::ToCStr; use std::ptr; #[link(name = "readline")] diff --git a/src/doc/guide.md b/src/doc/guide.md index f4ec787a794..e90f30cb864 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -26,7 +26,7 @@ in the `$`s, they just indicate the start of each command): curl -L https://static.rust-lang.org/rustup.sh | sudo sh ``` -If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`, +If you're concerned about the [potential insecurity](http://curlpipesh.tumblr.com/) of using `curl | sudo sh`, please keep reading and see our disclaimer below. And feel free to use a two-step version of the installation and examine our installation script: ```bash @@ -1109,10 +1109,11 @@ An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given time. Here's an example: ```{rust} +# use std::cmp::Ordering; fn cmp(a: int, b: int) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } fn main() { @@ -1121,11 +1122,11 @@ fn main() { let ordering = cmp(x, y); // ordering: Ordering - if ordering == Less { + if ordering == Ordering::Less { println!("less"); - } else if ordering == Greater { + } else if ordering == Ordering::Greater { println!("greater"); - } else if ordering == Equal { + } else if ordering == Ordering::Equal { println!("equal"); } } @@ -1280,10 +1281,11 @@ for every possible value of `x`, and so our program will compile successfully. section on enums? ```{rust} +# use std::cmp::Ordering; fn cmp(a: int, b: int) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } fn main() { @@ -1292,11 +1294,11 @@ fn main() { let ordering = cmp(x, y); - if ordering == Less { + if ordering == Ordering::Less { println!("less"); - } else if ordering == Greater { + } else if ordering == Ordering::Greater { println!("greater"); - } else if ordering == Equal { + } else if ordering == Ordering::Equal { println!("equal"); } } @@ -1305,10 +1307,11 @@ fn main() { We can re-write this as a `match`: ```{rust} +# use std::cmp::Ordering; fn cmp(a: int, b: int) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } fn main() { @@ -1316,9 +1319,9 @@ fn main() { let y = 10i; match cmp(x, y) { - Less => println!("less"), - Greater => println!("greater"), - Equal => println!("equal"), + Ordering::Less => println!("less"), + Ordering::Greater => println!("greater"), + Ordering::Equal => println!("equal"), } } ``` @@ -1365,10 +1368,11 @@ side of a `let` binding or directly where an expression is used. We could also implement the previous line like this: ```{rust} +# use std::cmp::Ordering; fn cmp(a: int, b: int) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } fn main() { @@ -1376,9 +1380,9 @@ fn main() { let y = 10i; println!("{}", match cmp(x, y) { - Less => "less", - Greater => "greater", - Equal => "equal", + Ordering::Less => "less", + Ordering::Greater => "greater", + Ordering::Equal => "equal", }); } ``` @@ -2139,6 +2143,7 @@ guess to the secret number: ```{rust,ignore} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2157,16 +2162,16 @@ fn main() { println!("You guessed: {}", input); match cmp(input, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } fn cmp(a: int, b: int) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2193,6 +2198,7 @@ we wrote the `cmp` function! Let's change it to take `uint`s: ```{rust,ignore} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2211,16 +2217,16 @@ fn main() { println!("You guessed: {}", input); match cmp(input, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2290,6 +2296,7 @@ Anyway, with us now converting our input to a number, our code looks like this: ```{rust,ignore} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2308,16 +2315,16 @@ fn main() { println!("You guessed: {}", input_num); match cmp(input_num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2339,6 +2346,7 @@ to do that. Try this code: ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2366,16 +2374,16 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2405,6 +2413,7 @@ code looks like this: ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2432,16 +2441,16 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2478,6 +2487,7 @@ Let's add that in: ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2507,17 +2517,17 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => println!("You win!"), + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => println!("You win!"), } } } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2553,6 +2563,7 @@ suboptimal to say the least. First, let's actually quit when you win the game: ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2582,9 +2593,9 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { println!("You win!"); return; }, @@ -2593,9 +2604,9 @@ fn main() { } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2608,6 +2619,7 @@ we don't want to quit, we just want to ignore it. Change that `return` to ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2637,9 +2649,9 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { println!("You win!"); return; }, @@ -2648,9 +2660,9 @@ fn main() { } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -2686,6 +2698,7 @@ It was good for testing, but it kind of ruins the game. Here's our final source: ```{rust,no_run} use std::io; use std::rand; +use std::cmp::Ordering; fn main() { println!("Guess the number!"); @@ -2713,9 +2726,9 @@ fn main() { println!("You guessed: {}", num); match cmp(num, secret_number) { - Less => println!("Too small!"), - Greater => println!("Too big!"), - Equal => { + Ordering::Less => println!("Too small!"), + Ordering::Greater => println!("Too big!"), + Ordering::Equal => { println!("You win!"); return; }, @@ -2724,9 +2737,9 @@ fn main() { } fn cmp(a: uint, b: uint) -> Ordering { - if a < b { Less } - else if a > b { Greater } - else { Equal } + if a < b { Ordering::Less } + else if a > b { Ordering::Greater } + else { Ordering::Equal } } ``` @@ -5217,7 +5230,7 @@ as you can see, there's no overhead of deciding which version to call here, hence 'statically dispatched'. The downside is that we have two copies of the same function, so our binary is a little bit larger. -# Threads +# Threads Concurrency and parallelism are topics that are of increasing interest to a broad subsection of software developers. Modern computers are often multi-core, diff --git a/src/doc/reference.md b/src/doc/reference.md index f3ad19bbd2a..7b3a0b74b8a 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -4149,11 +4149,11 @@ Unwinding the stack of a thread is done by the thread itself, on its own control stack. If a value with a destructor is freed during unwinding, the code for the destructor is run, also on the thread's control stack. Running the destructor code causes a temporary transition to a *running* state, and allows the -destructor code to cause any subsequent state transitions. The original thread +destructor code to cause any subsequent state transitions. The original thread of unwinding and panicking thereby may suspend temporarily, and may involve (recursive) unwinding of the stack of a failed destructor. Nonetheless, the outermost unwinding activity will continue until the stack is unwound and the -thread transitions to the *dead* state. There is no way to "recover" from thread +thread transitions to the *dead* state. There is no way to "recover" from thread panics. Once a thread has temporarily suspended its unwinding in the *panicking* state, a panic occurring from within this destructor results in *hard* panic. A hard panic currently results in the process aborting. |
