diff --git a/.travis.yml b/.travis.yml index cb1186689c..3810728b97 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,7 @@ language: node_js sudo: false install: - - curl -L https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly --yes --prefix=$PWD --disable-sudo --disable-ldconfig + - curl -L https://static.rust-lang.org/rustup.sh | sh -s -- --yes --prefix=$PWD --disable-sudo --disable-ldconfig - export PATH=$PATH:$PWD/bin - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/lib diff --git a/README.md b/README.md index 209c8cac9f..3f2b8b496c 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ See [CONTRIBUTING.md][how-to-contribute]. ### Debian (Ubuntu) prerequisites -Install Rust [nightly](http://www.rust-lang.org/install.html) and +Install [Rust](http://www.rust-lang.org/install.html) and run: ``` diff --git a/examples/README.md b/examples/README.md index de3c3ffc97..839f8b03a9 100644 --- a/examples/README.md +++ b/examples/README.md @@ -11,9 +11,6 @@ for this site][home]. Be sure to have Rust [installed][install] and the [docs][std] at hand, and let's start! -*Note*: Rust by Example uses the latest nightly build. If you're -following along on your computer, make sure to have it installed. - [rust]: http://www.rust-lang.org/ [install]: http://www.rust-lang.org/install.html [std]: http://doc.rust-lang.org/std/ diff --git a/examples/fn/closures/output_parameters/input.md b/examples/fn/closures/output_parameters/input.md deleted file mode 100644 index c650c58099..0000000000 --- a/examples/fn/closures/output_parameters/input.md +++ /dev/null @@ -1,30 +0,0 @@ -Closures as input parameters are possible so returning one should also be -possible. However, returning closure types are problematic because Rust -currently only supports returning concrete (non-generic) types. Anonymous -closure types are, by definition, unknown and so returning a closure is only -possible by making it concrete. This can be done via boxing. - -The valid types for returns are slightly different than before: - -* `Fn`: normal -* `FnMut`: normal -* `FnBox`: equivalent to `FnOnce` but specialized for this application -because `FnOnce` currently(version 1.1.0) interacts badly with the type system. - -Beyond this, the `move` keyword must be used which signals that all captures -occur by value. This is required because any captures by reference would be -dropped as soon as the function exited leaving invalid references in the -closure. - -{output_parameters.play} - -### See also: - -[Boxing][box], [`Fn`][fn], [`FnMut`][fnmut], [`FnBox`][fnbox], and -[Generics][generics] - -[box]: /std/box.html -[fn]: http://doc.rust-lang.org/std/ops/trait.Fn.html -[fnmut]: http://doc.rust-lang.org/std/ops/trait.FnMut.html -[fnbox]: http://doc.rust-lang.org/std/boxed/trait.FnBox.html -[generics]: /generics.html diff --git a/examples/fn/closures/output_parameters/output_parameters.rs b/examples/fn/closures/output_parameters/output_parameters.rs deleted file mode 100644 index 5452cb4f12..0000000000 --- a/examples/fn/closures/output_parameters/output_parameters.rs +++ /dev/null @@ -1,33 +0,0 @@ -#![feature(fnbox)] - -use std::boxed::FnBox; - -// Return a closure taking no inputs and returning nothing -// which implements `FnBox` (capture by value). -fn create_fnbox() -> Box { - let text = "FnBox".to_owned(); - - Box::new(move || println!("This is a: {}", text)) -} - -fn create_fn() -> Box { - let text = "Fn".to_owned(); - - Box::new(move || println!("This is a: {}", text)) -} - -fn create_fnmut() -> Box { - let text = "FnMut".to_owned(); - - Box::new(move || println!("This is a: {}", text)) -} - -fn main() { - let fn_plain = create_fn(); - let mut fn_mut = create_fnmut(); - let fn_box = create_fnbox(); - - fn_plain(); - fn_mut(); - fn_box(); -} diff --git a/examples/fn/hof/hof.rs b/examples/fn/hof/hof.rs index 592cfea45d..a0ce5aaf58 100644 --- a/examples/fn/hof/hof.rs +++ b/examples/fn/hof/hof.rs @@ -1,5 +1,3 @@ -#![feature(iter_arith)] - fn main() { println!("Find the sum of all the squared odd numbers under 1000"); let upper = 1000; @@ -27,7 +25,7 @@ fn main() { (0..).map(|n| n * n) // All natural numbers squared .take_while(|&n| n < upper) // Below upper limit .filter(|n| is_odd(*n)) // That are odd - .sum(); // Sum them + .fold(0, |sum, i| sum + i); // Sum them println!("functional style: {}", sum_of_squared_odd_numbers); } diff --git a/examples/generics/assoc_items/consts/consts.rs b/examples/generics/assoc_items/consts/consts.rs deleted file mode 100644 index 49743612e9..0000000000 --- a/examples/generics/assoc_items/consts/consts.rs +++ /dev/null @@ -1,40 +0,0 @@ -#![feature(associated_consts)] - -// 2 null structs. -#[allow(dead_code)] -struct Num; -#[allow(dead_code)] -struct Weird; - -// Trait to define zero. -trait Zero { - // `const` requires a type. Use a default of `0`. - const ZERO: i32 = 0; -} - -// Trait to define one. -trait One { - // Can use the type `Self` which defers to the `impl`. - const ONE: Self; -} - -// Use the default. -impl Zero for Num {} - -// Change the default. -impl Zero for Weird { - const ZERO: i32 = 9; -} - -// Define one for `i32`. -impl One for i32 { - // Type must agree with the `Self` type: `i32`. - const ONE: i32 = 1; -} - -fn main() { - // These calls use the `UFCS` calling syntax. - println!("ZERO for Num is {}", Num::ZERO); // Default. - println!("ZERO for Weird is {}", Weird::ZERO); // Customized. - println!("ONE for i32 is {}", i32::ONE); // Type specified in `impl`. -} diff --git a/examples/generics/assoc_items/consts/input.md b/examples/generics/assoc_items/consts/input.md deleted file mode 100644 index a3bf4b92c3..0000000000 --- a/examples/generics/assoc_items/consts/input.md +++ /dev/null @@ -1,7 +0,0 @@ -`trait`s holding `const`s are called Associated `const`s: - -{consts.play} - -### See also: - -[UFCS RFC](/~https://github.com/rust-lang/rfcs/blob/master/text/0132-ufcs.md) diff --git a/examples/meta/bench/bench.rs b/examples/meta/bench/bench.rs deleted file mode 100644 index f549587fbf..0000000000 --- a/examples/meta/bench/bench.rs +++ /dev/null @@ -1,55 +0,0 @@ -#![feature(test)] - -extern crate test; - -use std::mem::replace; -use test::Bencher; - -// bench: find the `BENCH_SIZE` first terms of the fibonacci sequence -static BENCH_SIZE: usize = 20; - -// recursive fibonacci -fn fibonacci(n: usize) -> u32 { - if n < 2 { - 1 - } else { - fibonacci(n - 1) + fibonacci(n - 2) - } -} - -// iterative fibonacci -struct Fibonacci { - curr: u32, - next: u32, -} - -impl Iterator for Fibonacci { - type Item = u32; - fn next(&mut self) -> Option { - let new_next = self.curr + self.next; - let new_curr = replace(&mut self.next, new_next); - - Some(replace(&mut self.curr, new_curr)) - } -} - -fn fibonacci_sequence() -> Fibonacci { - Fibonacci { curr: 1, next: 1 } -} - -// function to benchmark must be annotated with `#[bench]` -#[bench] -fn recursive_fibonacci(b: &mut Bencher) { - // exact code to benchmark must be passed as a closure to the iter - // method of Bencher - b.iter(|| { - (0..BENCH_SIZE).map(fibonacci).collect::>() - }) -} - -#[bench] -fn iterative_fibonacci(b: &mut Bencher) { - b.iter(|| { - fibonacci_sequence().take(BENCH_SIZE).collect::>() - }) -} diff --git a/examples/meta/bench/input.md b/examples/meta/bench/input.md deleted file mode 100644 index 20c5e6517c..0000000000 --- a/examples/meta/bench/input.md +++ /dev/null @@ -1,17 +0,0 @@ -Rust provides infrastructure for benchmarking via the `Bencher` struct and -the `#[bench]` attribute. Details in the source code below. - -{bench.rs} - -The source needs to be compiled using the `--test` flag, and the `--bench` flag -must be passed to the resulting binary. - -``` bash -$ rustc --test -O bench.rs -$ ./bench --bench -running 2 tests -test iterative_fibonacci ... bench: 191 ns/iter (+/- 16) -test recursive_fibonacci ... bench: 49670 ns/iter (+/- 522) - -test result: ok. 0 passed; 0 failed; 0 ignored; 2 measured -``` diff --git a/examples/std_misc/arg/matching/match_args.rs b/examples/std_misc/arg/matching/match_args.rs index 6d7abcf458..b77136ad3e 100644 --- a/examples/std_misc/arg/matching/match_args.rs +++ b/examples/std_misc/arg/matching/match_args.rs @@ -1,5 +1,3 @@ -#![feature(slice_patterns)] - use std::env; fn increase(number: i32) { @@ -21,21 +19,23 @@ match_args {{increase|decrease}} fn main() { let args: Vec = env::args().collect(); - match &args[..] { + match args.len() { // no arguments passed - [ref name] => { - println!("My name is '{}'. Try passing some arguments!", name); + 1 => { + println!("My name is 'match_args'. Try passing some arguments!"); }, // one argument passed - [_, ref string] => { - if string == &"42" { + 2 => { + if &42 == &args[1].parse().unwrap() { println!("This is the answer!"); } else { println!("This is not the answer."); } }, // one command and one argument passed - [_, ref cmd, ref num] => { + 3 => { + let cmd = &args[1]; + let num = &args[2]; // parse the number let number: i32 = match num.parse() { Ok(n) => { diff --git a/examples/std_misc/fs/fs.rs b/examples/std_misc/fs/fs.rs index 66f6b32c5e..3f7d63cc49 100644 --- a/examples/std_misc/fs/fs.rs +++ b/examples/std_misc/fs/fs.rs @@ -1,5 +1,3 @@ -#![feature(fs_walk)] - use std::fs; use std::fs::{File, OpenOptions}; use std::io; @@ -80,16 +78,6 @@ fn main() { }, } - println!("`walk a`"); - // Recursively walk over the contents of a directory, returns - // `Directories`, which implements the `Iterator trait - match fs::walk_dir("a") { - Err(why) => println!("! {:?}", why.kind()), - Ok(paths) => for path in paths { - println!("> {:?}", path.unwrap().path()); - }, - } - println!("`rm a/c/e.txt`"); // Remove a file, returns `io::Result<()>` fs::remove_file("a/c/e.txt").unwrap_or_else(|why| { diff --git a/examples/std_misc/path/path.rs b/examples/std_misc/path/path.rs index 73c5226053..ab183f10a4 100644 --- a/examples/std_misc/path/path.rs +++ b/examples/std_misc/path/path.rs @@ -1,7 +1,4 @@ -#![feature(path_ext)] - use std::path::Path; -use std::fs::PathExt; fn main() { // Create a `Path` from an `&'static str` @@ -10,21 +7,6 @@ fn main() { // The `display` method returns a `Show`able structure let display = path.display(); - // Check if the path exists - if path.exists() { - println!("{} exists", display); - } - - // Check if the path is a file - if path.is_file() { - println!("{} is a file", display); - } - - // Check if the path is a directory - if path.is_dir() { - println!("{} is a directory", display); - } - // `join` merges a path with a byte container using the OS specific // separator, and returns the new path let new_path = path.join("a").join("b"); diff --git a/examples/std_misc/simd/input.md b/examples/std_misc/simd/input.md deleted file mode 100644 index 312f14886f..0000000000 --- a/examples/std_misc/simd/input.md +++ /dev/null @@ -1,25 +0,0 @@ -Rust provides experimental support for SIMD vectors. These SIMD vectors are -exposed as structs (`f32x4`, `u8x16`, etc.) that implement basic operations -(`+`, `-`, `*`, etc) using SIMD instructions under the hood. - -{simd.rs} - -{simd.out} - -Here's a more complex example that sums two `Vec`, using the `f32x4` type -to operate on 4-element chunks at a time. - -{simd_add.rs} - -And here's the result of the benchmark: - -``` -$ rustc -O --test simd_add.rs && ./simd_add --bench -running 4 tests -test test::simd ... ignored -test test::vanilla ... ignored -test bench::simd ... bench: 1852 ns/iter (+/- 17) -test bench::vanilla ... bench: 8346 ns/iter (+/- 103) - -test result: ok. 0 passed; 0 failed; 2 ignored; 2 measured -``` diff --git a/examples/std_misc/simd/simd.rs b/examples/std_misc/simd/simd.rs deleted file mode 100644 index 144f8f4e5e..0000000000 --- a/examples/std_misc/simd/simd.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(core_simd)] - -use std::simd::f32x4; - -fn main() { - // create simd vectors - let x = f32x4(1.0, 2.0, 3.0, 4.0); - let y = f32x4(4.0, 3.0, 2.0, 1.0); - - // simd product - let z = x * y; - - // like any struct, the simd vector can be destructured using `let` - let f32x4(a, b, c, d) = z; - - println!("{:?}", (a, b, c, d)); -} diff --git a/examples/std_misc/simd/simd_add.rs b/examples/std_misc/simd/simd_add.rs deleted file mode 100644 index 71eeb5863f..0000000000 --- a/examples/std_misc/simd/simd_add.rs +++ /dev/null @@ -1,82 +0,0 @@ -#![feature(test)] -#![feature(core_simd)] - -use std::simd::f32x4; - -macro_rules! assert_equal_len { - ($a:ident, $b: ident) => { - assert!($a.len() == $b.len(), - "add_assign: dimension mismatch: {:?} += {:?}", - ($a.len(),), - ($b.len(),)); - } -} - -// element-wise addition -fn add_assign(xs: &mut Vec, ys: &Vec) { - assert_equal_len!(xs, ys); - - for (x, y) in xs.iter_mut().zip(ys.iter()) { - *x += *y; - } -} - -// simd accelerated addition -fn simd_add_assign(xs: &mut Vec, ys: &Vec) { - assert_equal_len!(xs, ys); - - let size = xs.len() as isize; - let chunks = size / 4; - - // pointer to the start of the vector data - let p_x: *mut f32 = xs.as_mut_ptr(); - let p_y: *const f32 = ys.as_ptr(); - - // sum excess elements that don't fit in the simd vector - for i in (4 * chunks)..size { - // dereferencing a raw pointer requires an unsafe block - unsafe { - // offset by i elements - *p_x.offset(i) += *p_y.offset(i); - } - } - - // treat f32 vector as an simd f32x4 vector - let simd_p_x = p_x as *mut f32x4; - let simd_p_y = p_y as *const f32x4; - - // sum "simd vector" - for i in 0..chunks { - unsafe { - *simd_p_x.offset(i) += *simd_p_y.offset(i); - } - } -} - -mod bench { - extern crate test; - use self::test::Bencher; - use std::iter; - static BENCH_SIZE: usize = 10_000; - - macro_rules! bench { - ($name:ident, $func:ident) => { - #[bench] - fn $name(b: &mut Bencher) { - let mut x: Vec<_> = iter::repeat(1.0f32) - .take(BENCH_SIZE) - .collect(); - let y: Vec<_> = iter::repeat(1.0f32) - .take(BENCH_SIZE) - .collect(); - - b.iter(|| { - super::$func(&mut x, &y); - }) - } - } - } - - bench!(vanilla, add_assign); - bench!(simd, simd_add_assign); -} diff --git a/examples/unsafe/asm.rs b/examples/unsafe/asm.rs deleted file mode 100644 index bc34dd086c..0000000000 --- a/examples/unsafe/asm.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(asm)] - -fn add(a: i32, b: i32) -> i32 { - let sum: i32; - unsafe { - asm!("add $2, $1; mov $1, $0" : "=r"(sum) : "r"(a), "r"(b)); - } - sum -} diff --git a/node_modules/gitbook-plugin-rust-playpen/book/editor.js b/node_modules/gitbook-plugin-rust-playpen/book/editor.js index 5afe0e5419..0d37c05cb3 100644 --- a/node_modules/gitbook-plugin-rust-playpen/book/editor.js +++ b/node_modules/gitbook-plugin-rust-playpen/book/editor.js @@ -159,7 +159,7 @@ function escapeHTML(unsafe) { function runProgram(program, callback) { var req = new XMLHttpRequest(); var data = JSON.stringify({ - version: "nightly", + version: "stable", optimize: "0", code: program }); diff --git a/src/example.rs b/src/example.rs index cf4cf0f795..c5918ca0a4 100644 --- a/src/example.rs +++ b/src/example.rs @@ -37,7 +37,7 @@ impl Example { None => 1, Some(ref children) => 1 + children.iter() .map(|c| c.count()) - .sum::(), + .fold(0, |sum, i| sum + i), } } diff --git a/src/main.rs b/src/main.rs index 08d1892c2b..54f7ea1d0e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,5 @@ -#![feature(iter_arith)] - #![deny(warnings)] #![allow(deprecated)] -#![feature(plugin)] extern crate regex; extern crate rustc_serialize;